Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept const components prop for Trans. #1224

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface TransProps<E extends Element = HTMLDivElement>
extends React.HTMLProps<E>,
Partial<WithT> {
children?: React.ReactNode;
components?: readonly React.ReactNode[] | { [tagName: string]: React.ReactNode };
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
count?: number;
defaults?: string;
i18n?: i18n;
Expand Down
2 changes: 1 addition & 1 deletion src/ts4.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface TransProps<
E extends Element = HTMLDivElement
> extends React.HTMLProps<E> {
children?: React.ReactNode;
components?: React.ReactNode[] | { [tagName: string]: React.ReactNode };
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
count?: number;
defaults?: string;
i18n?: i18n;
Expand Down
7 changes: 7 additions & 0 deletions test/typescript/Trans.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ function objectComponents() {
return <Trans components={{ Btn: <button /> }} defaults="Hello <Btn />" />;
}

function constObjectComponents() {
const constObject = {
Btn: <button />,
} as const;
return <Trans components={constObject} defaults="Hello <Btn />" />;
}

function count() {
return <Trans count={42}>Foo</Trans>;
}
Expand Down