Skip to content

Commit 988cd3f

Browse files
authored
fix #1899 (#1900)
1 parent 3b4e102 commit 988cd3f

File tree

7 files changed

+70
-5
lines changed

7 files changed

+70
-5
lines changed

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface IcuTransContentDeclaration {
4747
* Props for IcuTransWithoutContext component (no React context)
4848
*/
4949
export type IcuTransWithoutContextProps<
50-
Key extends ParseKeys<Ns, TOpt, KPrefix> = string,
50+
Key extends ParseKeys<Ns, TOpt, KPrefix>,
5151
Ns extends Namespace = _DefaultNamespace,
5252
KPrefix = undefined,
5353
TContext extends string | undefined = undefined,
@@ -73,7 +73,7 @@ export type IcuTransWithoutContextProps<
7373
* Props for IcuTrans component (with React context support)
7474
*/
7575
export type IcuTransProps<
76-
Key extends ParseKeys<Ns, TOpt, KPrefix> = string,
76+
Key extends ParseKeys<Ns, TOpt, KPrefix>,
7777
Ns extends Namespace = _DefaultNamespace,
7878
KPrefix = undefined,
7979
TContext extends string | undefined = undefined,
@@ -96,7 +96,7 @@ export type IcuTransProps<
9696
*/
9797
export interface IcuTransComponent {
9898
<
99-
Key extends ParseKeys<Ns, TOpt, KPrefix> = string,
99+
Key extends ParseKeys<Ns, TOpt, KPrefix>,
100100
Ns extends Namespace = _DefaultNamespace,
101101
KPrefix = undefined,
102102
TContext extends string | undefined = undefined,
@@ -123,7 +123,7 @@ export interface IcuTransComponent {
123123
*/
124124
export interface IcuTransWithoutContextComponent {
125125
<
126-
Key extends ParseKeys<Ns, TOpt, KPrefix> = string,
126+
Key extends ParseKeys<Ns, TOpt, KPrefix>,
127127
Ns extends Namespace = _DefaultNamespace,
128128
KPrefix = undefined,
129129
TContext extends string | undefined = undefined,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@
158158
"postversion": "npm run fix_dist_package && git push && git push --tags",
159159
"test": "vitest",
160160
"test:coverage": "npm run test -- --coverage --run",
161-
"test:typescript": "vitest --workspace vitest.workspace.typescript.mts",
161+
"test:typescript": "npm run test:typescript:issue-1899 && vitest --workspace vitest.workspace.typescript.mts",
162+
"test:typescript:issue-1899": "bash test/typescript/issue-1899/check-types.sh",
162163
"contributors:add": "all-contributors add",
163164
"contributors:generate": "all-contributors generate",
164165
"prepare": "husky"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Test script for issue #1899
3+
# https://github.com/i18next/react-i18next/issues/1899
4+
#
5+
# This script runs TypeScript with skipLibCheck: false and checks for errors
6+
# in index.d.ts. It ignores errors in node_modules (like @types/node issues).
7+
8+
set -e
9+
10+
cd "$(dirname "$0")/../../.."
11+
12+
# Run tsc and capture output
13+
OUTPUT=$(npx tsc -p test/typescript/issue-1899/tsconfig.json --noEmit 2>&1 || true)
14+
15+
# Check for errors in index.d.ts (our code)
16+
INDEX_ERRORS=$(echo "$OUTPUT" | grep "^index.d.ts" || true)
17+
18+
if [ -n "$INDEX_ERRORS" ]; then
19+
echo "ERROR: Type errors found in index.d.ts:"
20+
echo "$INDEX_ERRORS"
21+
exit 1
22+
fi
23+
24+
echo "OK: No type errors in index.d.ts"
25+
exit 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'i18next';
2+
3+
/**
4+
* Issue #1899: Type errors when custom resources are declared
5+
* https://github.com/i18next/react-i18next/issues/1899
6+
*
7+
* This configuration reproduces the bug where declaring custom resources
8+
* causes type errors in IcuTrans type definitions.
9+
*/
10+
declare module 'i18next' {
11+
interface CustomTypeOptions {
12+
defaultNS: 'app';
13+
resources: {
14+
app: { foo: string; bar: string };
15+
};
16+
}
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Issue #1899: Type errors when custom resources are declared
3+
* https://github.com/i18next/react-i18next/issues/1899
4+
*
5+
* This file imports from react-i18next to trigger TypeScript to check
6+
* the type definitions in index.d.ts with custom resources declared.
7+
*/
8+
import type { IcuTrans } from 'react-i18next';
9+
10+
// Just need to reference the type to trigger the check
11+
export type _Check = typeof IcuTrans;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../../tsconfig.json",
3+
"compilerOptions": {
4+
"skipLibCheck": false
5+
},
6+
"include": ["./**/*"],
7+
"exclude": []
8+
}

vitest.workspace.typescript.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default defineWorkspace(
99
*/
1010
readdirSync('./test/typescript', { withFileTypes: true })
1111
.filter((dir) => dir.isDirectory())
12+
// Exclude issue-1899 - it runs separately via test:typescript:issue-1899
13+
// because it requires skipLibCheck: false which exposes @types/node errors
14+
.filter((dir) => dir.name !== 'issue-1899')
1215
.reduce<UserProjectConfigExport[]>((workspaces, dir) => {
1316
const dirPath = `test/typescript/${dir.name}` as const;
1417

0 commit comments

Comments
 (0)