mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fixed array expression spreads into variadic const calls (#52845)
This commit is contained in:
@@ -29712,9 +29712,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const elementFlags: ElementFlags[] = [];
|
||||
pushCachedContextualType(node);
|
||||
const inDestructuringPattern = isAssignmentTarget(node);
|
||||
const inConstContext = isConstContext(node);
|
||||
const isSpreadIntoCallOrNew = isSpreadElement(node.parent) && isCallOrNewExpression(node.parent.parent);
|
||||
const inConstContext = isSpreadIntoCallOrNew || isConstContext(node);
|
||||
const contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
|
||||
const inTupleContext = !!contextualType && someType(contextualType, isTupleLikeType);
|
||||
const inTupleContext = isSpreadIntoCallOrNew || !!contextualType && someType(contextualType, isTupleLikeType);
|
||||
let hasOmittedExpression = false;
|
||||
for (let i = 0; i < elementCount; i++) {
|
||||
const e = elements[i];
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
tests/cases/conformance/es6/spread/arraySpreadInCall.ts(21,12): error TS2554: Expected 0-1 arguments, but got 2.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/spread/arraySpreadInCall.ts (1 errors) ====
|
||||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||
f1(1, 2, 3, 4, ...[5, 6]);
|
||||
f1(...[1], 2, 3, 4, 5, 6);
|
||||
f1(1, 2, ...[3, 4], 5, 6);
|
||||
f1(1, 2, ...[3], 4, ...[5, 6]);
|
||||
f1(...[1, 2], ...[3, 4], ...[5, 6]);
|
||||
|
||||
declare function f2<T extends unknown[]>(...args: T): T;
|
||||
const x21 = f2(...[1, 'foo'])
|
||||
const x22 = f2(true, ...[1, 'foo'])
|
||||
|
||||
declare function f3<T extends readonly unknown[]>(...args: T): T;
|
||||
const x31 = f3(...[1, 'foo'])
|
||||
const x32 = f3(true, ...[1, 'foo'])
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
run(event?: unknown): unknown;
|
||||
}
|
||||
declare const action: IAction
|
||||
action.run(...[100, 'foo']) // error
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2554: Expected 0-1 arguments, but got 2.
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
=== tests/cases/conformance/es6/spread/arraySpreadInCall.ts ===
|
||||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(arraySpreadInCall.ts, 0, 20))
|
||||
>b : Symbol(b, Decl(arraySpreadInCall.ts, 0, 30))
|
||||
>c : Symbol(c, Decl(arraySpreadInCall.ts, 0, 41))
|
||||
>d : Symbol(d, Decl(arraySpreadInCall.ts, 0, 52))
|
||||
>e : Symbol(e, Decl(arraySpreadInCall.ts, 0, 63))
|
||||
>f : Symbol(f, Decl(arraySpreadInCall.ts, 0, 74))
|
||||
|
||||
f1(1, 2, 3, 4, ...[5, 6]);
|
||||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0))
|
||||
|
||||
f1(...[1], 2, 3, 4, 5, 6);
|
||||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0))
|
||||
|
||||
f1(1, 2, ...[3, 4], 5, 6);
|
||||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0))
|
||||
|
||||
f1(1, 2, ...[3], 4, ...[5, 6]);
|
||||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0))
|
||||
|
||||
f1(...[1, 2], ...[3, 4], ...[5, 6]);
|
||||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0))
|
||||
|
||||
declare function f2<T extends unknown[]>(...args: T): T;
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 7, 20))
|
||||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 7, 41))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 7, 20))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 7, 20))
|
||||
|
||||
const x21 = f2(...[1, 'foo'])
|
||||
>x21 : Symbol(x21, Decl(arraySpreadInCall.ts, 8, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36))
|
||||
|
||||
const x22 = f2(true, ...[1, 'foo'])
|
||||
>x22 : Symbol(x22, Decl(arraySpreadInCall.ts, 9, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36))
|
||||
|
||||
declare function f3<T extends readonly unknown[]>(...args: T): T;
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 11, 20))
|
||||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 11, 50))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 11, 20))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 11, 20))
|
||||
|
||||
const x31 = f3(...[1, 'foo'])
|
||||
>x31 : Symbol(x31, Decl(arraySpreadInCall.ts, 12, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35))
|
||||
|
||||
const x32 = f3(true, ...[1, 'foo'])
|
||||
>x32 : Symbol(x32, Decl(arraySpreadInCall.ts, 13, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35))
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 13, 35))
|
||||
|
||||
run(event?: unknown): unknown;
|
||||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19))
|
||||
>event : Symbol(event, Decl(arraySpreadInCall.ts, 17, 8))
|
||||
}
|
||||
declare const action: IAction
|
||||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 19, 13))
|
||||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 13, 35))
|
||||
|
||||
action.run(...[100, 'foo']) // error
|
||||
>action.run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19))
|
||||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 19, 13))
|
||||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19))
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
=== tests/cases/conformance/es6/spread/arraySpreadInCall.ts ===
|
||||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void
|
||||
>a : number
|
||||
>b : number
|
||||
>c : number
|
||||
>d : number
|
||||
>e : number
|
||||
>f : number
|
||||
|
||||
f1(1, 2, 3, 4, ...[5, 6]);
|
||||
>f1(1, 2, 3, 4, ...[5, 6]) : void
|
||||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...[5, 6] : number
|
||||
>[5, 6] : readonly [number, number]
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
f1(...[1], 2, 3, 4, 5, 6);
|
||||
>f1(...[1], 2, 3, 4, 5, 6) : void
|
||||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void
|
||||
>...[1] : number
|
||||
>[1] : readonly [number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
f1(1, 2, ...[3, 4], 5, 6);
|
||||
>f1(1, 2, ...[3, 4], 5, 6) : void
|
||||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...[3, 4] : number
|
||||
>[3, 4] : readonly [number, number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
f1(1, 2, ...[3], 4, ...[5, 6]);
|
||||
>f1(1, 2, ...[3], 4, ...[5, 6]) : void
|
||||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...[3] : number
|
||||
>[3] : readonly [number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...[5, 6] : number
|
||||
>[5, 6] : readonly [number, number]
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
f1(...[1, 2], ...[3, 4], ...[5, 6]);
|
||||
>f1(...[1, 2], ...[3, 4], ...[5, 6]) : void
|
||||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...[3, 4] : number
|
||||
>[3, 4] : readonly [number, number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...[5, 6] : number
|
||||
>[5, 6] : readonly [number, number]
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
declare function f2<T extends unknown[]>(...args: T): T;
|
||||
>f2 : <T extends unknown[]>(...args: T) => T
|
||||
>args : T
|
||||
|
||||
const x21 = f2(...[1, 'foo'])
|
||||
>x21 : [number, string]
|
||||
>f2(...[1, 'foo']) : [number, string]
|
||||
>f2 : <T extends unknown[]>(...args: T) => T
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x22 = f2(true, ...[1, 'foo'])
|
||||
>x22 : [boolean, number, string]
|
||||
>f2(true, ...[1, 'foo']) : [boolean, number, string]
|
||||
>f2 : <T extends unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
declare function f3<T extends readonly unknown[]>(...args: T): T;
|
||||
>f3 : <T extends readonly unknown[]>(...args: T) => T
|
||||
>args : T
|
||||
|
||||
const x31 = f3(...[1, 'foo'])
|
||||
>x31 : [number, string]
|
||||
>f3(...[1, 'foo']) : [number, string]
|
||||
>f3 : <T extends readonly unknown[]>(...args: T) => T
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x32 = f3(true, ...[1, 'foo'])
|
||||
>x32 : [boolean, number, string]
|
||||
>f3(true, ...[1, 'foo']) : [boolean, number, string]
|
||||
>f3 : <T extends readonly unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
run(event?: unknown): unknown;
|
||||
>run : (event?: unknown) => unknown
|
||||
>event : unknown
|
||||
}
|
||||
declare const action: IAction
|
||||
>action : IAction
|
||||
|
||||
action.run(...[100, 'foo']) // error
|
||||
>action.run(...[100, 'foo']) : unknown
|
||||
>action.run : (event?: unknown) => unknown
|
||||
>action : IAction
|
||||
>run : (event?: unknown) => unknown
|
||||
>...[100, 'foo'] : string | number
|
||||
>[100, 'foo'] : readonly [number, string]
|
||||
>100 : 100
|
||||
>'foo' : "foo"
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ o1?.(...[1, 2]);
|
||||
>o1?.(...[1, 2]) : number | undefined
|
||||
>o1 : ((...args: any[]) => number) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : number[]
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
@@ -25,7 +25,7 @@ o1?.(1, ...[2, 3], 4);
|
||||
>o1 : ((...args: any[]) => number) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : number[]
|
||||
>[2, 3] : readonly [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -54,7 +54,7 @@ o2?.b(...[1, 2]);
|
||||
>o2 : { b: (...args: any[]) => number; } | undefined
|
||||
>b : ((...args: any[]) => number) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : number[]
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
@@ -65,7 +65,7 @@ o2?.b(1, ...[2, 3], 4);
|
||||
>b : ((...args: any[]) => number) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : number[]
|
||||
>[2, 3] : readonly [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -89,7 +89,7 @@ o2?.["b"](...[1, 2]);
|
||||
>o2 : { b: (...args: any[]) => number; } | undefined
|
||||
>"b" : "b"
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : number[]
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
@@ -100,7 +100,7 @@ o2?.["b"](1, ...[2, 3], 4);
|
||||
>"b" : "b"
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : number[]
|
||||
>[2, 3] : readonly [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -135,7 +135,7 @@ o3.b?.(...[1, 2]).c;
|
||||
>o3 : { b: ((...args: any[]) => { c: string; }) | undefined; }
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : number[]
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>c : string | undefined
|
||||
@@ -148,7 +148,7 @@ o3.b?.(1, ...[2, 3], 4).c;
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : number[]
|
||||
>[2, 3] : readonly [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -178,7 +178,7 @@ o3.b?.(...[1, 2])["c"];
|
||||
>o3 : { b: ((...args: any[]) => { c: string; }) | undefined; }
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : number[]
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>"c" : "c"
|
||||
@@ -191,7 +191,7 @@ o3.b?.(1, ...[2, 3], 4)["c"];
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : number[]
|
||||
>[2, 3] : readonly [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -221,7 +221,7 @@ o3["b"]?.(...[1, 2]).c;
|
||||
>o3 : { b: ((...args: any[]) => { c: string; }) | undefined; }
|
||||
>"b" : "b"
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : number[]
|
||||
>[1, 2] : readonly [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>c : string | undefined
|
||||
@@ -234,7 +234,7 @@ o3["b"]?.(1, ...[2, 3], 4).c;
|
||||
>"b" : "b"
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : number[]
|
||||
>[2, 3] : readonly [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
|
||||
@@ -267,7 +267,7 @@ xa[1].foo(1, 2, ...a, "abc");
|
||||
>1 : 1
|
||||
>foo : (x: number, y: number, ...z: string[]) => X
|
||||
>...[1, 2, "abc"] : string | number
|
||||
>[1, 2, "abc"] : (string | number)[]
|
||||
>[1, 2, "abc"] : readonly [number, number, string]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>"abc" : "abc"
|
||||
|
||||
@@ -159,7 +159,7 @@ xa[1].foo(1, 2, ...a, "abc");
|
||||
>1 : 1
|
||||
>foo : (x: number, y: number, ...z: string[]) => any
|
||||
>...[1, 2, "abc"] : string | number
|
||||
>[1, 2, "abc"] : (string | number)[]
|
||||
>[1, 2, "abc"] : readonly [number, number, string]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>"abc" : "abc"
|
||||
|
||||
@@ -5,7 +5,7 @@ tests/cases/compiler/functionParameterArityMismatch.ts(11,1): error TS2575: No o
|
||||
tests/cases/compiler/functionParameterArityMismatch.ts(12,1): error TS2575: No overload expects 3 arguments, but overloads do exist that expect either 2 or 4 arguments.
|
||||
tests/cases/compiler/functionParameterArityMismatch.ts(13,1): error TS2575: No overload expects 5 arguments, but overloads do exist that expect either 4 or 6 arguments.
|
||||
tests/cases/compiler/functionParameterArityMismatch.ts(14,22): error TS2554: Expected 0-6 arguments, but got 7.
|
||||
tests/cases/compiler/functionParameterArityMismatch.ts(15,4): error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
|
||||
tests/cases/compiler/functionParameterArityMismatch.ts(15,19): error TS2554: Expected 0-6 arguments, but got 7.
|
||||
|
||||
|
||||
==== tests/cases/compiler/functionParameterArityMismatch.ts (8 errors) ====
|
||||
@@ -38,7 +38,7 @@ tests/cases/compiler/functionParameterArityMismatch.ts(15,4): error TS2556: A sp
|
||||
f2(1, 2, 3, 4, 5, 6, 7);
|
||||
~
|
||||
!!! error TS2554: Expected 0-6 arguments, but got 7.
|
||||
f2(...[1], 2, 3, 4, 5, 6);
|
||||
~~~~~~
|
||||
!!! error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
|
||||
f2(1, 2, 3, 4, 5, ...[6, 7]);
|
||||
~~~~~~~~~
|
||||
!!! error TS2554: Expected 0-6 arguments, but got 7.
|
||||
|
||||
@@ -13,7 +13,7 @@ f2(1);
|
||||
f2(1, 2, 3);
|
||||
f2(1, 2, 3, 4, 5);
|
||||
f2(1, 2, 3, 4, 5, 6, 7);
|
||||
f2(...[1], 2, 3, 4, 5, 6);
|
||||
f2(1, 2, 3, 4, 5, ...[6, 7]);
|
||||
|
||||
|
||||
//// [functionParameterArityMismatch.js]
|
||||
@@ -33,4 +33,4 @@ f2(1);
|
||||
f2(1, 2, 3);
|
||||
f2(1, 2, 3, 4, 5);
|
||||
f2(1, 2, 3, 4, 5, 6, 7);
|
||||
f2.apply(void 0, __spreadArray(__spreadArray([], [1], false), [2, 3, 4, 5, 6], false));
|
||||
f2.apply(void 0, __spreadArray([1, 2, 3, 4, 5], [6, 7], false));
|
||||
|
||||
@@ -54,6 +54,6 @@ f2(1, 2, 3, 4, 5);
|
||||
f2(1, 2, 3, 4, 5, 6, 7);
|
||||
>f2 : Symbol(f2, Decl(functionParameterArityMismatch.ts, 4, 15), Decl(functionParameterArityMismatch.ts, 6, 22), Decl(functionParameterArityMismatch.ts, 7, 42), Decl(functionParameterArityMismatch.ts, 8, 64))
|
||||
|
||||
f2(...[1], 2, 3, 4, 5, 6);
|
||||
f2(1, 2, 3, 4, 5, ...[6, 7]);
|
||||
>f2 : Symbol(f2, Decl(functionParameterArityMismatch.ts, 4, 15), Decl(functionParameterArityMismatch.ts, 6, 22), Decl(functionParameterArityMismatch.ts, 7, 42), Decl(functionParameterArityMismatch.ts, 8, 64))
|
||||
|
||||
|
||||
@@ -83,15 +83,16 @@ f2(1, 2, 3, 4, 5, 6, 7);
|
||||
>6 : 6
|
||||
>7 : 7
|
||||
|
||||
f2(...[1], 2, 3, 4, 5, 6);
|
||||
>f2(...[1], 2, 3, 4, 5, 6) : any
|
||||
f2(1, 2, 3, 4, 5, ...[6, 7]);
|
||||
>f2(1, 2, 3, 4, 5, ...[6, 7]) : any
|
||||
>f2 : { (): any; (a: number, b: number): any; (a: number, b: number, c: number, d: number): any; (a: number, b: number, c: number, d: number, e: number, f: number): any; }
|
||||
>...[1] : number
|
||||
>[1] : number[]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>5 : 5
|
||||
>...[6, 7] : number
|
||||
>[6, 7] : readonly [number, number]
|
||||
>6 : 6
|
||||
>7 : 7
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ var a = ["./0"];
|
||||
import(...["PathModule"]);
|
||||
>import(...["PathModule"]) : Promise<any>
|
||||
>...["PathModule"] : string
|
||||
>["PathModule"] : string[]
|
||||
>["PathModule"] : readonly [string]
|
||||
>"PathModule" : "PathModule"
|
||||
|
||||
var p1 = import(...a);
|
||||
|
||||
@@ -73,7 +73,7 @@ new Foo(...[...new SymbolIterator, ...[...new _StringIterator]]);
|
||||
>new Foo(...[...new SymbolIterator, ...[...new _StringIterator]]) : Foo<string | symbol>
|
||||
>Foo : typeof Foo
|
||||
>...[...new SymbolIterator, ...[...new _StringIterator]] : string | symbol
|
||||
>[...new SymbolIterator, ...[...new _StringIterator]] : (string | symbol)[]
|
||||
>[...new SymbolIterator, ...[...new _StringIterator]] : readonly (string | symbol)[]
|
||||
>...new SymbolIterator : symbol
|
||||
>new SymbolIterator : SymbolIterator
|
||||
>SymbolIterator : typeof SymbolIterator
|
||||
|
||||
@@ -76,7 +76,7 @@ new Foo(...new SymbolIterator, ...[...new _StringIterator]);
|
||||
>new SymbolIterator : SymbolIterator
|
||||
>SymbolIterator : typeof SymbolIterator
|
||||
>...[...new _StringIterator] : string
|
||||
>[...new _StringIterator] : string[]
|
||||
>[...new _StringIterator] : readonly string[]
|
||||
>...new _StringIterator : string
|
||||
>new _StringIterator : _StringIterator
|
||||
>_StringIterator : typeof _StringIterator
|
||||
|
||||
@@ -1491,7 +1491,7 @@ function f1(thing: Thing) {
|
||||
>path : { <T, K1 extends keyof T>(obj: T, key1: K1): T[K1]; <T, K1 extends keyof T, K2 extends keyof T[K1]>(obj: T, key1: K1, key2: K2): T[K1][K2]; <T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(obj: T, key1: K1, key2: K2, key3: K3): T[K1][K2][K3]; (obj: any, ...keys: (string | number)[]): any; }
|
||||
>thing : Thing
|
||||
>...['a', 'x'] : string
|
||||
>['a', 'x'] : string[]
|
||||
>['a', 'x'] : readonly [string, string]
|
||||
>'a' : "a"
|
||||
>'x' : "x"
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ function foo(set: any) {
|
||||
>set : any
|
||||
>values : any
|
||||
>push : any
|
||||
>...[] : undefined
|
||||
>[] : undefined[]
|
||||
>...[] : never
|
||||
>[] : readonly []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -620,8 +620,8 @@ const trinaryDynamicImport = import('1', '2', '3')
|
||||
const spreadDynamicImport = import(...[])
|
||||
>spreadDynamicImport : Promise<any>
|
||||
>import(...[]) : Promise<any>
|
||||
>...[] : undefined
|
||||
>[] : undefined[]
|
||||
>...[] : never
|
||||
>[] : readonly []
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ declare function f25(...args,): void;
|
||||
f2(...[],);
|
||||
>f2(...[],) : void
|
||||
>f2 : (...args: any[]) => void
|
||||
>...[] : undefined
|
||||
>[] : undefined[]
|
||||
>...[] : never
|
||||
>[] : readonly []
|
||||
|
||||
// Not confused by overloads
|
||||
declare function f3(x, ): number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts(45,14): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts(51,9): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts(47,14): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts(53,9): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts (2 errors) ====
|
||||
@@ -33,6 +33,8 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterCon
|
||||
declare function f6<const T extends readonly unknown[]>(...args: T): T;
|
||||
|
||||
const x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
const x62 = f6(...[1, 'b']);
|
||||
const x63 = f6(true, ...[1, 'b']);
|
||||
|
||||
class C1<const T> {
|
||||
constructor(x: T) {}
|
||||
|
||||
@@ -29,6 +29,8 @@ const x52 = f5({ x: { a: 1, b: 'x' }, y: { a: 2, b: 'y' } });
|
||||
declare function f6<const T extends readonly unknown[]>(...args: T): T;
|
||||
|
||||
const x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
const x62 = f6(...[1, 'b']);
|
||||
const x63 = f6(true, ...[1, 'b']);
|
||||
|
||||
class C1<const T> {
|
||||
constructor(x: T) {}
|
||||
@@ -85,6 +87,15 @@ const test2 = inners2([1,2,3,4,5]);
|
||||
|
||||
//// [typeParameterConstModifiers.js]
|
||||
"use strict";
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
var x11 = f1('a');
|
||||
var x12 = f1(['a', ['b', 'c']]);
|
||||
var x13 = f1({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
|
||||
@@ -98,6 +109,8 @@ var x42 = f4([{ a: 1, b: 'x' }, { a: 2, b: 'y' }]);
|
||||
var x51 = f5({ x: [1, 'x'], y: [2, 'y'] });
|
||||
var x52 = f5({ x: { a: 1, b: 'x' }, y: { a: 2, b: 'y' } });
|
||||
var x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
var x62 = f6.apply(void 0, [1, 'b']);
|
||||
var x63 = f6.apply(void 0, __spreadArray([true], [1, 'b'], false));
|
||||
var C1 = /** @class */ (function () {
|
||||
function C1(x) {
|
||||
}
|
||||
|
||||
@@ -120,179 +120,187 @@ const x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 29, 24))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 29, 30))
|
||||
|
||||
const x62 = f6(...[1, 'b']);
|
||||
>x62 : Symbol(x62, Decl(typeParameterConstModifiers.ts, 30, 5))
|
||||
>f6 : Symbol(f6, Decl(typeParameterConstModifiers.ts, 25, 61))
|
||||
|
||||
const x63 = f6(true, ...[1, 'b']);
|
||||
>x63 : Symbol(x63, Decl(typeParameterConstModifiers.ts, 31, 5))
|
||||
>f6 : Symbol(f6, Decl(typeParameterConstModifiers.ts, 25, 61))
|
||||
|
||||
class C1<const T> {
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 29, 41))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 31, 9))
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 31, 34))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 33, 9))
|
||||
|
||||
constructor(x: T) {}
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 32, 16))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 31, 9))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 34, 16))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 33, 9))
|
||||
|
||||
foo<const U>(x: U) { return x; }
|
||||
>foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 32, 24))
|
||||
>U : Symbol(U, Decl(typeParameterConstModifiers.ts, 33, 8))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 33, 17))
|
||||
>U : Symbol(U, Decl(typeParameterConstModifiers.ts, 33, 8))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 33, 17))
|
||||
>foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 34, 24))
|
||||
>U : Symbol(U, Decl(typeParameterConstModifiers.ts, 35, 8))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 35, 17))
|
||||
>U : Symbol(U, Decl(typeParameterConstModifiers.ts, 35, 8))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 35, 17))
|
||||
}
|
||||
|
||||
const c71 = new C1({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
|
||||
>c71 : Symbol(c71, Decl(typeParameterConstModifiers.ts, 36, 5))
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 29, 41))
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 36, 20))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 36, 26))
|
||||
>d : Symbol(d, Decl(typeParameterConstModifiers.ts, 36, 34))
|
||||
>f : Symbol(f, Decl(typeParameterConstModifiers.ts, 36, 54))
|
||||
>c71 : Symbol(c71, Decl(typeParameterConstModifiers.ts, 38, 5))
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 31, 34))
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 38, 20))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 38, 26))
|
||||
>d : Symbol(d, Decl(typeParameterConstModifiers.ts, 38, 34))
|
||||
>f : Symbol(f, Decl(typeParameterConstModifiers.ts, 38, 54))
|
||||
|
||||
const c72 = c71.foo(['a', ['b', 'c']]);
|
||||
>c72 : Symbol(c72, Decl(typeParameterConstModifiers.ts, 37, 5))
|
||||
>c71.foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 32, 24))
|
||||
>c71 : Symbol(c71, Decl(typeParameterConstModifiers.ts, 36, 5))
|
||||
>foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 32, 24))
|
||||
>c72 : Symbol(c72, Decl(typeParameterConstModifiers.ts, 39, 5))
|
||||
>c71.foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 34, 24))
|
||||
>c71 : Symbol(c71, Decl(typeParameterConstModifiers.ts, 38, 5))
|
||||
>foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 34, 24))
|
||||
|
||||
const C2 = class <const T> {}
|
||||
>C2 : Symbol(C2, Decl(typeParameterConstModifiers.ts, 39, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 39, 18))
|
||||
>C2 : Symbol(C2, Decl(typeParameterConstModifiers.ts, 41, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 41, 18))
|
||||
|
||||
const fx1 = <const T>(x: T) => x;
|
||||
>fx1 : Symbol(fx1, Decl(typeParameterConstModifiers.ts, 41, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 41, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 41, 22))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 41, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 41, 22))
|
||||
>fx1 : Symbol(fx1, Decl(typeParameterConstModifiers.ts, 43, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 43, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 43, 22))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 43, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 43, 22))
|
||||
|
||||
const fx2 = <const T,>(x: T) => x;
|
||||
>fx2 : Symbol(fx2, Decl(typeParameterConstModifiers.ts, 42, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 42, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 42, 23))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 42, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 42, 23))
|
||||
>fx2 : Symbol(fx2, Decl(typeParameterConstModifiers.ts, 44, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 44, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 44, 23))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 44, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 44, 23))
|
||||
|
||||
interface I1<const T> { x: T } // Error
|
||||
>I1 : Symbol(I1, Decl(typeParameterConstModifiers.ts, 42, 34))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 44, 13))
|
||||
>x : Symbol(I1.x, Decl(typeParameterConstModifiers.ts, 44, 23))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 44, 13))
|
||||
>I1 : Symbol(I1, Decl(typeParameterConstModifiers.ts, 44, 34))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 46, 13))
|
||||
>x : Symbol(I1.x, Decl(typeParameterConstModifiers.ts, 46, 23))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 46, 13))
|
||||
|
||||
interface I2 {
|
||||
>I2 : Symbol(I2, Decl(typeParameterConstModifiers.ts, 44, 30))
|
||||
>I2 : Symbol(I2, Decl(typeParameterConstModifiers.ts, 46, 30))
|
||||
|
||||
f<const T>(x: T): T;
|
||||
>f : Symbol(I2.f, Decl(typeParameterConstModifiers.ts, 46, 14))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 47, 6))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 47, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 47, 6))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 47, 6))
|
||||
>f : Symbol(I2.f, Decl(typeParameterConstModifiers.ts, 48, 14))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 49, 6))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 49, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 49, 6))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 49, 6))
|
||||
}
|
||||
|
||||
type T1<const T> = T; // Error
|
||||
>T1 : Symbol(T1, Decl(typeParameterConstModifiers.ts, 48, 1))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 50, 8))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 50, 8))
|
||||
>T1 : Symbol(T1, Decl(typeParameterConstModifiers.ts, 50, 1))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 8))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 8))
|
||||
|
||||
type T2 = <const T>(x: T) => T;
|
||||
>T2 : Symbol(T2, Decl(typeParameterConstModifiers.ts, 50, 21))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 11))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 52, 20))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 11))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 11))
|
||||
>T2 : Symbol(T2, Decl(typeParameterConstModifiers.ts, 52, 21))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 11))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 54, 20))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 11))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 11))
|
||||
|
||||
type T3 = { <const T>(x: T): T };
|
||||
>T3 : Symbol(T3, Decl(typeParameterConstModifiers.ts, 52, 31))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 53, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 53, 22))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 53, 13))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 53, 13))
|
||||
>T3 : Symbol(T3, Decl(typeParameterConstModifiers.ts, 54, 31))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 55, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 55, 22))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 55, 13))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 55, 13))
|
||||
|
||||
type T4 = new <const T>(x: T) => T;
|
||||
>T4 : Symbol(T4, Decl(typeParameterConstModifiers.ts, 53, 33))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 15))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 54, 24))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 15))
|
||||
>T4 : Symbol(T4, Decl(typeParameterConstModifiers.ts, 55, 33))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 56, 15))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 56, 24))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 56, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 56, 15))
|
||||
|
||||
type T5 = { new <const T>(x: T): T };
|
||||
>T5 : Symbol(T5, Decl(typeParameterConstModifiers.ts, 54, 35))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 55, 17))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 55, 26))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 55, 17))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 55, 17))
|
||||
>T5 : Symbol(T5, Decl(typeParameterConstModifiers.ts, 56, 35))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 57, 17))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 57, 26))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 57, 17))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 57, 17))
|
||||
|
||||
// Corrected repro from #51745
|
||||
|
||||
type Obj = { a: { b: { c: "123" } } };
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 55, 37))
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 59, 12))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 59, 17))
|
||||
>c : Symbol(c, Decl(typeParameterConstModifiers.ts, 59, 22))
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 57, 37))
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 61, 12))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 61, 17))
|
||||
>c : Symbol(c, Decl(typeParameterConstModifiers.ts, 61, 22))
|
||||
|
||||
type GetPath<T, P> =
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 59, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 61, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 61, 15))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 61, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 63, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 63, 15))
|
||||
|
||||
P extends readonly [] ? T :
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 61, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 61, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 63, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 63, 13))
|
||||
|
||||
P extends readonly [infer A extends keyof T, ...infer Rest] ? GetPath<T[A], Rest> :
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 61, 15))
|
||||
>A : Symbol(A, Decl(typeParameterConstModifiers.ts, 63, 29))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 61, 13))
|
||||
>Rest : Symbol(Rest, Decl(typeParameterConstModifiers.ts, 63, 57))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 59, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 61, 13))
|
||||
>A : Symbol(A, Decl(typeParameterConstModifiers.ts, 63, 29))
|
||||
>Rest : Symbol(Rest, Decl(typeParameterConstModifiers.ts, 63, 57))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 63, 15))
|
||||
>A : Symbol(A, Decl(typeParameterConstModifiers.ts, 65, 29))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 63, 13))
|
||||
>Rest : Symbol(Rest, Decl(typeParameterConstModifiers.ts, 65, 57))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 61, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 63, 13))
|
||||
>A : Symbol(A, Decl(typeParameterConstModifiers.ts, 65, 29))
|
||||
>Rest : Symbol(Rest, Decl(typeParameterConstModifiers.ts, 65, 57))
|
||||
|
||||
never;
|
||||
|
||||
function set<T, const P extends readonly string[]>(obj: T, path: P, value: GetPath<T, P>) {}
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 64, 10))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 66, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 66, 15))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 66, 51))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 66, 13))
|
||||
>path : Symbol(path, Decl(typeParameterConstModifiers.ts, 66, 58))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 66, 15))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 66, 67))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 59, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 66, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 66, 15))
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 66, 10))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 68, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 68, 15))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 68, 51))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 68, 13))
|
||||
>path : Symbol(path, Decl(typeParameterConstModifiers.ts, 68, 58))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 68, 15))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 68, 67))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 61, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 68, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 68, 15))
|
||||
|
||||
declare let obj: Obj;
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 68, 11))
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 55, 37))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 70, 11))
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 57, 37))
|
||||
|
||||
declare let value: "123";
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 69, 11))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 71, 11))
|
||||
|
||||
set(obj, ['a', 'b', 'c'], value);
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 64, 10))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 68, 11))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 69, 11))
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 66, 10))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 70, 11))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 71, 11))
|
||||
|
||||
// Repro from #52007
|
||||
|
||||
declare function inners<const T extends readonly any[]>(...args: readonly [unknown, ...T, unknown]): T;
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 71, 33))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 75, 24))
|
||||
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 75, 56))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 75, 24))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 75, 24))
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 73, 33))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 77, 24))
|
||||
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 77, 56))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 77, 24))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 77, 24))
|
||||
|
||||
const test = inners(1,2,3,4,5);
|
||||
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 77, 5))
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 71, 33))
|
||||
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 79, 5))
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 73, 33))
|
||||
|
||||
declare function inners2<const T extends readonly any[]>(args: readonly [unknown, ...T, unknown]): T;
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 77, 31))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 79, 25))
|
||||
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 79, 57))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 79, 25))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 79, 25))
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 79, 31))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 81, 25))
|
||||
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 81, 57))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 81, 25))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 81, 25))
|
||||
|
||||
const test2 = inners2([1,2,3,4,5]);
|
||||
>test2 : Symbol(test2, Decl(typeParameterConstModifiers.ts, 81, 5))
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 77, 31))
|
||||
>test2 : Symbol(test2, Decl(typeParameterConstModifiers.ts, 83, 5))
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 79, 31))
|
||||
|
||||
|
||||
@@ -177,6 +177,25 @@ const x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
>b : "x"
|
||||
>'x' : "x"
|
||||
|
||||
const x62 = f6(...[1, 'b']);
|
||||
>x62 : readonly [number, string]
|
||||
>f6(...[1, 'b']) : readonly [number, string]
|
||||
>f6 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>...[1, 'b'] : string | number
|
||||
>[1, 'b'] : readonly [number, string]
|
||||
>1 : 1
|
||||
>'b' : "b"
|
||||
|
||||
const x63 = f6(true, ...[1, 'b']);
|
||||
>x63 : readonly [true, number, string]
|
||||
>f6(true, ...[1, 'b']) : readonly [true, number, string]
|
||||
>f6 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'b'] : string | number
|
||||
>[1, 'b'] : readonly [number, string]
|
||||
>1 : 1
|
||||
>'b' : "b"
|
||||
|
||||
class C1<const T> {
|
||||
>C1 : C1<T>
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@ f2(1);
|
||||
f2(1, 2, 3);
|
||||
f2(1, 2, 3, 4, 5);
|
||||
f2(1, 2, 3, 4, 5, 6, 7);
|
||||
f2(...[1], 2, 3, 4, 5, 6);
|
||||
f2(1, 2, 3, 4, 5, ...[6, 7]);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
|
||||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||
f1(1, 2, 3, 4, ...[5, 6]);
|
||||
f1(...[1], 2, 3, 4, 5, 6);
|
||||
f1(1, 2, ...[3, 4], 5, 6);
|
||||
f1(1, 2, ...[3], 4, ...[5, 6]);
|
||||
f1(...[1, 2], ...[3, 4], ...[5, 6]);
|
||||
|
||||
declare function f2<T extends unknown[]>(...args: T): T;
|
||||
const x21 = f2(...[1, 'foo'])
|
||||
const x22 = f2(true, ...[1, 'foo'])
|
||||
|
||||
declare function f3<T extends readonly unknown[]>(...args: T): T;
|
||||
const x31 = f3(...[1, 'foo'])
|
||||
const x32 = f3(true, ...[1, 'foo'])
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
run(event?: unknown): unknown;
|
||||
}
|
||||
declare const action: IAction
|
||||
action.run(...[100, 'foo']) // error
|
||||
|
||||
+2
@@ -30,6 +30,8 @@ const x52 = f5({ x: { a: 1, b: 'x' }, y: { a: 2, b: 'y' } });
|
||||
declare function f6<const T extends readonly unknown[]>(...args: T): T;
|
||||
|
||||
const x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
const x62 = f6(...[1, 'b']);
|
||||
const x63 = f6(true, ...[1, 'b']);
|
||||
|
||||
class C1<const T> {
|
||||
constructor(x: T) {}
|
||||
|
||||
Reference in New Issue
Block a user