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

Stricter typescript type for Trans components prop #1516

Merged
merged 4 commits into from Jun 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -34,7 +34,7 @@ export interface TransProps<E extends Element = HTMLDivElement>
extends React.HTMLProps<E>,
Partial<WithT> {
children?: React.ReactNode;
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
count?: number;
context?: string;
defaults?: string;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -117,9 +117,9 @@
"test:watch": "cross-env BABEL_ENV=development jest --no-cache --watch",
"test:coverage": "cross-env BABEL_ENV=development jest --no-cache --coverage",
"test:lint": "eslint ./src ./test",
"test:typescript": "tslint --project tsconfig.json '**/*.ts'",
"test:typescript:noninterop": "tslint --project tsconfig.nonEsModuleInterop.json '**/*.ts'",
"test:typescript:customtypes": "tslint --project ./test/typescript/custom-types/tsconfig.json '**/*.ts'",
"test:typescript": "tslint --project tsconfig.json '**/*.{ts,tsx}'",
"test:typescript:noninterop": "tslint --project tsconfig.nonEsModuleInterop.json '**/*.{ts,tsx}'",
"test:typescript:customtypes": "tslint --project ./test/typescript/custom-types/tsconfig.json '**/*.{ts,tsx}'",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"prettier": "prettier --write \"{,**/}*.{ts,tsx,js,json,md}\""
Expand Down
8 changes: 8 additions & 0 deletions test/typescript/Trans.test.tsx
Expand Up @@ -26,6 +26,14 @@ function objectComponents() {
return <Trans components={{ Btn: <button /> }} defaults="Hello <Btn />" />;
}

function MyComponent() {
return <>world</>;
}

function objectCustomComponents() {
return <Trans components={{ Btn: <MyComponent /> }} defaults="Hello <Btn />" />;
}

function constObjectComponents() {
const constObject = {
Btn: <button />,
Expand Down
2 changes: 1 addition & 1 deletion ts4.1/index.d.ts
Expand Up @@ -264,7 +264,7 @@ export type TransProps<
E = React.HTMLProps<HTMLDivElement>
> = E & {
children?: TransChild | TransChild[];
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
count?: number;
context?: string;
defaults?: string;
Expand Down