add extra test cases for contextual parameters
This commit is contained in:
Родитель
90572e4de6
Коммит
7be81d5ae9
|
@ -13,7 +13,10 @@ noInferRestSpread1.ts(7,22): error TS2345: Argument of type '(a: number, b: numb
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '(a: number, b: number) => void' is not assignable to parameter of type '(args_0: number) => void'.
|
||||
!!! error TS2345: Target signature provides too few arguments. Expected 2 or more, but got 1.
|
||||
const result3 = call((a, b) => {}, 1, '');; // test contextual parameters
|
||||
const result3 = call((a) => {}, 1, ''); // test contextual parameters
|
||||
const result4 = call((a, b) => {}, 1, ''); // test contextual parameters
|
||||
const result5 = call((...args) => {}, 1, ''); // test contextual parameters
|
||||
const result6 = call((a, ...rest) => {}, 1, ''); // test contextual parameters
|
||||
|
||||
declare function fn1<A extends unknown[]>(
|
||||
cb: (a: [number, ...NoInfer<A>]) => void,
|
||||
|
@ -22,13 +25,13 @@ noInferRestSpread1.ts(7,22): error TS2345: Argument of type '(a: number, b: numb
|
|||
|
||||
declare const singleStr: [string];
|
||||
|
||||
const result4 = fn1((arg) => {
|
||||
const result7 = fn1((arg) => {
|
||||
arg.length;
|
||||
}, singleStr);
|
||||
|
||||
declare const tupleUnion: [string] | [number, boolean];
|
||||
|
||||
const result5 = fn1((arg) => {
|
||||
const result8 = fn1((arg) => {
|
||||
arg.length;
|
||||
}, tupleUnion);
|
||||
|
||||
|
|
|
@ -29,69 +29,85 @@ const result2 = call((a: number, b: number) => {}, 1); // error
|
|||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 6, 22))
|
||||
>b : Symbol(b, Decl(noInferRestSpread1.ts, 6, 32))
|
||||
|
||||
const result3 = call((a, b) => {}, 1, '');; // test contextual parameters
|
||||
const result3 = call((a) => {}, 1, ''); // test contextual parameters
|
||||
>result3 : Symbol(result3, Decl(noInferRestSpread1.ts, 7, 5))
|
||||
>call : Symbol(call, Decl(noInferRestSpread1.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 7, 22))
|
||||
>b : Symbol(b, Decl(noInferRestSpread1.ts, 7, 24))
|
||||
|
||||
const result4 = call((a, b) => {}, 1, ''); // test contextual parameters
|
||||
>result4 : Symbol(result4, Decl(noInferRestSpread1.ts, 8, 5))
|
||||
>call : Symbol(call, Decl(noInferRestSpread1.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 8, 22))
|
||||
>b : Symbol(b, Decl(noInferRestSpread1.ts, 8, 24))
|
||||
|
||||
const result5 = call((...args) => {}, 1, ''); // test contextual parameters
|
||||
>result5 : Symbol(result5, Decl(noInferRestSpread1.ts, 9, 5))
|
||||
>call : Symbol(call, Decl(noInferRestSpread1.ts, 0, 0))
|
||||
>args : Symbol(args, Decl(noInferRestSpread1.ts, 9, 22))
|
||||
|
||||
const result6 = call((a, ...rest) => {}, 1, ''); // test contextual parameters
|
||||
>result6 : Symbol(result6, Decl(noInferRestSpread1.ts, 10, 5))
|
||||
>call : Symbol(call, Decl(noInferRestSpread1.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 10, 22))
|
||||
>rest : Symbol(rest, Decl(noInferRestSpread1.ts, 10, 24))
|
||||
|
||||
declare function fn1<A extends unknown[]>(
|
||||
>fn1 : Symbol(fn1, Decl(noInferRestSpread1.ts, 7, 43))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 9, 21))
|
||||
>fn1 : Symbol(fn1, Decl(noInferRestSpread1.ts, 10, 48))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 12, 21))
|
||||
|
||||
cb: (a: [number, ...NoInfer<A>]) => void,
|
||||
>cb : Symbol(cb, Decl(noInferRestSpread1.ts, 9, 42))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 10, 7))
|
||||
>cb : Symbol(cb, Decl(noInferRestSpread1.ts, 12, 42))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 13, 7))
|
||||
>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 9, 21))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 12, 21))
|
||||
|
||||
args: A,
|
||||
>args : Symbol(args, Decl(noInferRestSpread1.ts, 10, 43))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 9, 21))
|
||||
>args : Symbol(args, Decl(noInferRestSpread1.ts, 13, 43))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 12, 21))
|
||||
|
||||
): A;
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 9, 21))
|
||||
>A : Symbol(A, Decl(noInferRestSpread1.ts, 12, 21))
|
||||
|
||||
declare const singleStr: [string];
|
||||
>singleStr : Symbol(singleStr, Decl(noInferRestSpread1.ts, 14, 13))
|
||||
>singleStr : Symbol(singleStr, Decl(noInferRestSpread1.ts, 17, 13))
|
||||
|
||||
const result4 = fn1((arg) => {
|
||||
>result4 : Symbol(result4, Decl(noInferRestSpread1.ts, 16, 5))
|
||||
>fn1 : Symbol(fn1, Decl(noInferRestSpread1.ts, 7, 43))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 16, 21))
|
||||
const result7 = fn1((arg) => {
|
||||
>result7 : Symbol(result7, Decl(noInferRestSpread1.ts, 19, 5))
|
||||
>fn1 : Symbol(fn1, Decl(noInferRestSpread1.ts, 10, 48))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 19, 21))
|
||||
|
||||
arg.length;
|
||||
>arg.length : Symbol(length)
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 16, 21))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 19, 21))
|
||||
>length : Symbol(length)
|
||||
|
||||
}, singleStr);
|
||||
>singleStr : Symbol(singleStr, Decl(noInferRestSpread1.ts, 14, 13))
|
||||
>singleStr : Symbol(singleStr, Decl(noInferRestSpread1.ts, 17, 13))
|
||||
|
||||
declare const tupleUnion: [string] | [number, boolean];
|
||||
>tupleUnion : Symbol(tupleUnion, Decl(noInferRestSpread1.ts, 20, 13))
|
||||
>tupleUnion : Symbol(tupleUnion, Decl(noInferRestSpread1.ts, 23, 13))
|
||||
|
||||
const result5 = fn1((arg) => {
|
||||
>result5 : Symbol(result5, Decl(noInferRestSpread1.ts, 22, 5))
|
||||
>fn1 : Symbol(fn1, Decl(noInferRestSpread1.ts, 7, 43))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 22, 21))
|
||||
const result8 = fn1((arg) => {
|
||||
>result8 : Symbol(result8, Decl(noInferRestSpread1.ts, 25, 5))
|
||||
>fn1 : Symbol(fn1, Decl(noInferRestSpread1.ts, 10, 48))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 25, 21))
|
||||
|
||||
arg.length;
|
||||
>arg.length : Symbol(length)
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 22, 21))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 25, 21))
|
||||
>length : Symbol(length)
|
||||
|
||||
}, tupleUnion);
|
||||
>tupleUnion : Symbol(tupleUnion, Decl(noInferRestSpread1.ts, 20, 13))
|
||||
>tupleUnion : Symbol(tupleUnion, Decl(noInferRestSpread1.ts, 23, 13))
|
||||
|
||||
declare function fn2(arg: (...args: NoInfer<[string, number]>) => void): void;
|
||||
>fn2 : Symbol(fn2, Decl(noInferRestSpread1.ts, 24, 15))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 26, 21))
|
||||
>args : Symbol(args, Decl(noInferRestSpread1.ts, 26, 27))
|
||||
>fn2 : Symbol(fn2, Decl(noInferRestSpread1.ts, 27, 15))
|
||||
>arg : Symbol(arg, Decl(noInferRestSpread1.ts, 29, 21))
|
||||
>args : Symbol(args, Decl(noInferRestSpread1.ts, 29, 27))
|
||||
>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
fn2((a, ...rest) => {});
|
||||
>fn2 : Symbol(fn2, Decl(noInferRestSpread1.ts, 24, 15))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 28, 5))
|
||||
>rest : Symbol(rest, Decl(noInferRestSpread1.ts, 28, 7))
|
||||
>fn2 : Symbol(fn2, Decl(noInferRestSpread1.ts, 27, 15))
|
||||
>a : Symbol(a, Decl(noInferRestSpread1.ts, 31, 5))
|
||||
>rest : Symbol(rest, Decl(noInferRestSpread1.ts, 31, 7))
|
||||
|
||||
|
|
|
@ -49,9 +49,25 @@ const result2 = call((a: number, b: number) => {}, 1); // error
|
|||
>1 : 1
|
||||
> : ^
|
||||
|
||||
const result3 = call((a, b) => {}, 1, '');; // test contextual parameters
|
||||
const result3 = call((a) => {}, 1, ''); // test contextual parameters
|
||||
>result3 : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call((a) => {}, 1, '') : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call : <A extends readonly unknown[]>(arg: (...args: NoInfer<A>) => void, ...args: A) => A
|
||||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ ^^ ^^^^^
|
||||
>(a) => {} : (a: number) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^
|
||||
>a : number
|
||||
> : ^^^^^^
|
||||
>1 : 1
|
||||
> : ^
|
||||
>'' : ""
|
||||
> : ^^
|
||||
|
||||
const result4 = call((a, b) => {}, 1, ''); // test contextual parameters
|
||||
>result4 : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call((a, b) => {}, 1, '') : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call : <A extends readonly unknown[]>(arg: (...args: NoInfer<A>) => void, ...args: A) => A
|
||||
|
@ -67,6 +83,40 @@ const result3 = call((a, b) => {}, 1, '');; // test contextual parameters
|
|||
>'' : ""
|
||||
> : ^^
|
||||
|
||||
const result5 = call((...args) => {}, 1, ''); // test contextual parameters
|
||||
>result5 : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call((...args) => {}, 1, '') : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call : <A extends readonly unknown[]>(arg: (...args: NoInfer<A>) => void, ...args: A) => A
|
||||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ ^^ ^^^^^
|
||||
>(...args) => {} : (args_0: number, args_1: string) => void
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>args : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>1 : 1
|
||||
> : ^
|
||||
>'' : ""
|
||||
> : ^^
|
||||
|
||||
const result6 = call((a, ...rest) => {}, 1, ''); // test contextual parameters
|
||||
>result6 : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call((a, ...rest) => {}, 1, '') : [number, string]
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>call : <A extends readonly unknown[]>(arg: (...args: NoInfer<A>) => void, ...args: A) => A
|
||||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ ^^ ^^^^^
|
||||
>(a, ...rest) => {} : (a: number, rest_0: string) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>a : number
|
||||
> : ^^^^^^
|
||||
>rest : [string]
|
||||
> : ^^^^^^^^
|
||||
>1 : 1
|
||||
> : ^
|
||||
>'' : ""
|
||||
> : ^^
|
||||
|
||||
declare function fn1<A extends unknown[]>(
|
||||
>fn1 : <A extends unknown[]>(cb: (a: [number, ...NoInfer<A>]) => void, args: A) => A
|
||||
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^
|
||||
|
@ -87,8 +137,8 @@ declare const singleStr: [string];
|
|||
>singleStr : [string]
|
||||
> : ^^^^^^^^
|
||||
|
||||
const result4 = fn1((arg) => {
|
||||
>result4 : [string]
|
||||
const result7 = fn1((arg) => {
|
||||
>result7 : [string]
|
||||
> : ^^^^^^^^
|
||||
>fn1((arg) => { arg.length;}, singleStr) : [string]
|
||||
> : ^^^^^^^^
|
||||
|
@ -115,8 +165,8 @@ declare const tupleUnion: [string] | [number, boolean];
|
|||
>tupleUnion : [string] | [number, boolean]
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
const result5 = fn1((arg) => {
|
||||
>result5 : [string] | [number, boolean]
|
||||
const result8 = fn1((arg) => {
|
||||
>result8 : [string] | [number, boolean]
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>fn1((arg) => { arg.length;}, tupleUnion) : [string] | [number, boolean]
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -8,7 +8,10 @@ declare function call<A extends readonly unknown[]>(
|
|||
|
||||
const result1 = call((a: number) => {}, 1, 2);
|
||||
const result2 = call((a: number, b: number) => {}, 1); // error
|
||||
const result3 = call((a, b) => {}, 1, '');; // test contextual parameters
|
||||
const result3 = call((a) => {}, 1, ''); // test contextual parameters
|
||||
const result4 = call((a, b) => {}, 1, ''); // test contextual parameters
|
||||
const result5 = call((...args) => {}, 1, ''); // test contextual parameters
|
||||
const result6 = call((a, ...rest) => {}, 1, ''); // test contextual parameters
|
||||
|
||||
declare function fn1<A extends unknown[]>(
|
||||
cb: (a: [number, ...NoInfer<A>]) => void,
|
||||
|
@ -17,13 +20,13 @@ declare function fn1<A extends unknown[]>(
|
|||
|
||||
declare const singleStr: [string];
|
||||
|
||||
const result4 = fn1((arg) => {
|
||||
const result7 = fn1((arg) => {
|
||||
arg.length;
|
||||
}, singleStr);
|
||||
|
||||
declare const tupleUnion: [string] | [number, boolean];
|
||||
|
||||
const result5 = fn1((arg) => {
|
||||
const result8 = fn1((arg) => {
|
||||
arg.length;
|
||||
}, tupleUnion);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче