Skip to content

Commit

Permalink
Merge pull request #1224 from pcorpet/array-type
Browse files Browse the repository at this point in the history
Accept const components prop for Trans.
  • Loading branch information
jamuhl authored Dec 14, 2020
2 parents 59758d4 + 7de332c commit 6e9a17a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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

0 comments on commit 6e9a17a

Please sign in to comment.