Skip to content

Commit a186adb

Browse files
authored
SetParameterType: Fix compatibility with TypeScript 5.4 (#836)
1 parent 14fb192 commit a186adb

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"node": ">=16"
1717
},
1818
"scripts": {
19-
"test": "xo && tsd && tsc && node script/test/source-files-extension.js"
19+
"test": "xo && tsd && tsc && npm run test:set-parameter-type && node script/test/source-files-extension.js",
20+
"test:set-parameter-type": "tsc --noEmit test-d/set-parameter-type"
2021
},
2122
"files": [
2223
"index.d.ts",

source/set-parameter-type.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {IsUnknown} from './is-unknown';
2-
import type {StaticPartOfArray} from './internal';
2+
import type {StaticPartOfArray, VariablePartOfArray} from './internal';
33
import type {UnknownArray} from './unknown-array';
44

55
/**
@@ -32,7 +32,10 @@ type MergeObjectToArray<TArray extends UnknownArray, TObject, TArrayCopy extends
3232
? number extends TObject['length']
3333
? TObject
3434
: {
35-
[K in keyof TArray]: K extends keyof TObject ? TObject[K] : TArray[K]
35+
[K in keyof TArray]:
36+
number extends K
37+
? VariablePartOfArray<TArray>[number]
38+
: K extends keyof TObject ? TObject[K] : TArray[K]
3639
}
3740
: TObject extends object
3841
// If `TObject` is a object witch key is number like `{0: string, 1: number}`

test-d/set-parameter-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ expectType<(a: string, b: string, c: boolean, ...args: boolean[]) => null>(test2
2222
test2('1', '2', true, true);
2323

2424
// Test another define way
25-
declare const test3: SetParameterType<typeof fn, [a: string, b: boolean]>;
26-
expectType<(a: string, b: boolean, c: Object, ...args: boolean[]) => null>(test3);
27-
test3('1', true, {}, true);
25+
declare const test3: SetParameterType<typeof fn, [a: 'a', b: 'b']>;
26+
expectType<(a: 'a', b: 'b', c: Object, ...args: boolean[]) => null>(test3);
27+
test3('a', 'b', {}, true);
2828

2929
// Test `...args` parameter
3030
declare const testargs: SetParameterType<typeof fn, {3: string}>;

0 commit comments

Comments
 (0)