mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fixed parenthesized array literal expressions spread in calls not being tupleized (#54623)
This commit is contained in:
@@ -29965,6 +29965,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
(node.kind === SyntaxKind.BinaryExpression && (node as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken);
|
||||
}
|
||||
|
||||
function isSpreadIntoCallOrNew(node: ArrayLiteralExpression) {
|
||||
const parent = walkUpParenthesizedExpressions(node.parent);
|
||||
return isSpreadElement(parent) && isCallOrNewExpression(parent.parent);
|
||||
}
|
||||
|
||||
function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined, forceTuple: boolean | undefined): Type {
|
||||
const elements = node.elements;
|
||||
const elementCount = elements.length;
|
||||
@@ -29972,10 +29977,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const elementFlags: ElementFlags[] = [];
|
||||
pushCachedContextualType(node);
|
||||
const inDestructuringPattern = isAssignmentTarget(node);
|
||||
const isSpreadIntoCallOrNew = isSpreadElement(node.parent) && isCallOrNewExpression(node.parent.parent);
|
||||
const inConstContext = isSpreadIntoCallOrNew || isConstContext(node);
|
||||
const inConstContext = isConstContext(node);
|
||||
const contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
|
||||
const inTupleContext = isSpreadIntoCallOrNew || !!contextualType && someType(contextualType, isTupleLikeType);
|
||||
const inTupleContext = isSpreadIntoCallOrNew(node) || !!contextualType && someType(contextualType, isTupleLikeType);
|
||||
let hasOmittedExpression = false;
|
||||
for (let i = 0; i < elementCount; i++) {
|
||||
const e = elements[i];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
arraySpreadInCall.ts(21,12): error TS2554: Expected 0-1 arguments, but got 2.
|
||||
arraySpreadInCall.ts(32,12): error TS2554: Expected 0-1 arguments, but got 2.
|
||||
|
||||
|
||||
==== arraySpreadInCall.ts (1 errors) ====
|
||||
@@ -8,14 +8,25 @@ arraySpreadInCall.ts(21,12): error TS2554: Expected 0-1 arguments, but got 2.
|
||||
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'])
|
||||
const x23 = f2(...([1, 'foo']))
|
||||
const x24 = 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'])
|
||||
const x33 = f3(...([1, 'foo']))
|
||||
const x34 = f3(true, ...([1, 'foo']))
|
||||
|
||||
declare function f4<const T extends readonly unknown[]>(...args: T): T;
|
||||
const x41 = f4(...[1, 'foo'])
|
||||
const x42 = f4(true, ...[1, 'foo'])
|
||||
const x43 = f4(...([1, 'foo']))
|
||||
const x44 = f4(true, ...([1, 'foo']))
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
|
||||
@@ -25,51 +25,93 @@ f1(1, 2, ...[3], 4, ...[5, 6]);
|
||||
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))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 6, 50))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 8, 20))
|
||||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 8, 41))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 8, 20))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 8, 20))
|
||||
|
||||
const x21 = f2(...[1, 'foo'])
|
||||
>x21 : Symbol(x21, Decl(arraySpreadInCall.ts, 8, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36))
|
||||
>x21 : Symbol(x21, Decl(arraySpreadInCall.ts, 9, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 6, 50))
|
||||
|
||||
const x22 = f2(true, ...[1, 'foo'])
|
||||
>x22 : Symbol(x22, Decl(arraySpreadInCall.ts, 9, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36))
|
||||
>x22 : Symbol(x22, Decl(arraySpreadInCall.ts, 10, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 6, 50))
|
||||
|
||||
const x23 = f2(...([1, 'foo']))
|
||||
>x23 : Symbol(x23, Decl(arraySpreadInCall.ts, 11, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 6, 50))
|
||||
|
||||
const x24 = f2(true, ...([1, 'foo']))
|
||||
>x24 : Symbol(x24, Decl(arraySpreadInCall.ts, 12, 5))
|
||||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 6, 50))
|
||||
|
||||
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))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 12, 37))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 14, 20))
|
||||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 14, 50))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 14, 20))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 14, 20))
|
||||
|
||||
const x31 = f3(...[1, 'foo'])
|
||||
>x31 : Symbol(x31, Decl(arraySpreadInCall.ts, 12, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35))
|
||||
>x31 : Symbol(x31, Decl(arraySpreadInCall.ts, 15, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 12, 37))
|
||||
|
||||
const x32 = f3(true, ...[1, 'foo'])
|
||||
>x32 : Symbol(x32, Decl(arraySpreadInCall.ts, 13, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35))
|
||||
>x32 : Symbol(x32, Decl(arraySpreadInCall.ts, 16, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 12, 37))
|
||||
|
||||
const x33 = f3(...([1, 'foo']))
|
||||
>x33 : Symbol(x33, Decl(arraySpreadInCall.ts, 17, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 12, 37))
|
||||
|
||||
const x34 = f3(true, ...([1, 'foo']))
|
||||
>x34 : Symbol(x34, Decl(arraySpreadInCall.ts, 18, 5))
|
||||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 12, 37))
|
||||
|
||||
declare function f4<const T extends readonly unknown[]>(...args: T): T;
|
||||
>f4 : Symbol(f4, Decl(arraySpreadInCall.ts, 18, 37))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 20, 20))
|
||||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 20, 56))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 20, 20))
|
||||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 20, 20))
|
||||
|
||||
const x41 = f4(...[1, 'foo'])
|
||||
>x41 : Symbol(x41, Decl(arraySpreadInCall.ts, 21, 5))
|
||||
>f4 : Symbol(f4, Decl(arraySpreadInCall.ts, 18, 37))
|
||||
|
||||
const x42 = f4(true, ...[1, 'foo'])
|
||||
>x42 : Symbol(x42, Decl(arraySpreadInCall.ts, 22, 5))
|
||||
>f4 : Symbol(f4, Decl(arraySpreadInCall.ts, 18, 37))
|
||||
|
||||
const x43 = f4(...([1, 'foo']))
|
||||
>x43 : Symbol(x43, Decl(arraySpreadInCall.ts, 23, 5))
|
||||
>f4 : Symbol(f4, Decl(arraySpreadInCall.ts, 18, 37))
|
||||
|
||||
const x44 = f4(true, ...([1, 'foo']))
|
||||
>x44 : Symbol(x44, Decl(arraySpreadInCall.ts, 24, 5))
|
||||
>f4 : Symbol(f4, Decl(arraySpreadInCall.ts, 18, 37))
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 13, 35))
|
||||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 24, 37))
|
||||
|
||||
run(event?: unknown): unknown;
|
||||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19))
|
||||
>event : Symbol(event, Decl(arraySpreadInCall.ts, 17, 8))
|
||||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 27, 19))
|
||||
>event : Symbol(event, Decl(arraySpreadInCall.ts, 28, 8))
|
||||
}
|
||||
declare const action: IAction
|
||||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 19, 13))
|
||||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 13, 35))
|
||||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 30, 13))
|
||||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 24, 37))
|
||||
|
||||
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))
|
||||
>action.run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 27, 19))
|
||||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 30, 13))
|
||||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 27, 19))
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ f1(1, 2, 3, 4, ...[5, 6]);
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...[5, 6] : number
|
||||
>[5, 6] : readonly [number, number]
|
||||
>[5, 6] : [number, number]
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
@@ -26,7 +26,7 @@ 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] : [number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
@@ -40,7 +40,7 @@ f1(1, 2, ...[3, 4], 5, 6);
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...[3, 4] : number
|
||||
>[3, 4] : readonly [number, number]
|
||||
>[3, 4] : [number, number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>5 : 5
|
||||
@@ -52,11 +52,11 @@ f1(1, 2, ...[3], 4, ...[5, 6]);
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...[3] : number
|
||||
>[3] : readonly [number]
|
||||
>[3] : [number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...[5, 6] : number
|
||||
>[5, 6] : readonly [number, number]
|
||||
>[5, 6] : [number, number]
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
@@ -64,15 +64,38 @@ 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, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...[3, 4] : number
|
||||
>[3, 4] : readonly [number, number]
|
||||
>[3, 4] : [number, number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...[5, 6] : number
|
||||
>[5, 6] : readonly [number, number]
|
||||
>[5, 6] : [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])) : [number, number]
|
||||
>([1, 2]) : [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...(((([3, 4])))) : number
|
||||
>(((([3, 4])))) : [number, number]
|
||||
>((([3, 4]))) : [number, number]
|
||||
>(([3, 4])) : [number, number]
|
||||
>([3, 4]) : [number, number]
|
||||
>[3, 4] : [number, number]
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
>...([5, 6]) : number
|
||||
>([5, 6]) : [number, number]
|
||||
>[5, 6] : [number, number]
|
||||
>5 : 5
|
||||
>6 : 6
|
||||
|
||||
@@ -85,7 +108,7 @@ const x21 = f2(...[1, 'foo'])
|
||||
>f2(...[1, 'foo']) : [number, string]
|
||||
>f2 : <T extends unknown[]>(...args: T) => T
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
@@ -95,7 +118,28 @@ const x22 = f2(true, ...[1, 'foo'])
|
||||
>f2 : <T extends unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x23 = f2(...([1, 'foo']))
|
||||
>x23 : [number, string]
|
||||
>f2(...([1, 'foo'])) : [number, string]
|
||||
>f2 : <T extends unknown[]>(...args: T) => T
|
||||
>...([1, 'foo']) : string | number
|
||||
>([1, 'foo']) : [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x24 = f2(true, ...([1, 'foo']))
|
||||
>x24 : [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']) : [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
@@ -108,7 +152,7 @@ const x31 = f3(...[1, 'foo'])
|
||||
>f3(...[1, 'foo']) : [number, string]
|
||||
>f3 : <T extends readonly unknown[]>(...args: T) => T
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
@@ -118,7 +162,72 @@ const x32 = f3(true, ...[1, 'foo'])
|
||||
>f3 : <T extends readonly unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : readonly [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x33 = f3(...([1, 'foo']))
|
||||
>x33 : [number, string]
|
||||
>f3(...([1, 'foo'])) : [number, string]
|
||||
>f3 : <T extends readonly unknown[]>(...args: T) => T
|
||||
>...([1, 'foo']) : string | number
|
||||
>([1, 'foo']) : [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x34 = f3(true, ...([1, 'foo']))
|
||||
>x34 : [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']) : [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
declare function f4<const T extends readonly unknown[]>(...args: T): T;
|
||||
>f4 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>args : T
|
||||
|
||||
const x41 = f4(...[1, 'foo'])
|
||||
>x41 : readonly [number, string]
|
||||
>f4(...[1, 'foo']) : readonly [number, string]
|
||||
>f4 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x42 = f4(true, ...[1, 'foo'])
|
||||
>x42 : readonly [true, number, string]
|
||||
>f4(true, ...[1, 'foo']) : readonly [true, number, string]
|
||||
>f4 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'foo'] : string | number
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x43 = f4(...([1, 'foo']))
|
||||
>x43 : readonly [number, string]
|
||||
>f4(...([1, 'foo'])) : readonly [number, string]
|
||||
>f4 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>...([1, 'foo']) : string | number
|
||||
>([1, 'foo']) : [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
const x44 = f4(true, ...([1, 'foo']))
|
||||
>x44 : readonly [true, number, string]
|
||||
>f4(true, ...([1, 'foo'])) : readonly [true, number, string]
|
||||
>f4 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...([1, 'foo']) : string | number
|
||||
>([1, 'foo']) : [number, string]
|
||||
>[1, 'foo'] : [number, string]
|
||||
>1 : 1
|
||||
>'foo' : "foo"
|
||||
|
||||
@@ -137,7 +246,7 @@ action.run(...[100, 'foo']) // error
|
||||
>action : IAction
|
||||
>run : (event?: unknown) => unknown
|
||||
>...[100, 'foo'] : string | number
|
||||
>[100, 'foo'] : readonly [number, string]
|
||||
>[100, 'foo'] : [number, string]
|
||||
>100 : 100
|
||||
>'foo' : "foo"
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ o1?.(...[1, 2]);
|
||||
>o1?.(...[1, 2]) : number | undefined
|
||||
>o1 : ((...args: any[]) => number) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
@@ -27,7 +27,7 @@ o1?.(1, ...[2, 3], 4);
|
||||
>o1 : ((...args: any[]) => number) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : readonly [number, number]
|
||||
>[2, 3] : [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -56,7 +56,7 @@ o2?.b(...[1, 2]);
|
||||
>o2 : { b: (...args: any[]) => number; } | undefined
|
||||
>b : ((...args: any[]) => number) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
@@ -67,7 +67,7 @@ o2?.b(1, ...[2, 3], 4);
|
||||
>b : ((...args: any[]) => number) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : readonly [number, number]
|
||||
>[2, 3] : [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -91,7 +91,7 @@ o2?.["b"](...[1, 2]);
|
||||
>o2 : { b: (...args: any[]) => number; } | undefined
|
||||
>"b" : "b"
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
@@ -102,7 +102,7 @@ o2?.["b"](1, ...[2, 3], 4);
|
||||
>"b" : "b"
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : readonly [number, number]
|
||||
>[2, 3] : [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -137,7 +137,7 @@ o3.b?.(...[1, 2]).c;
|
||||
>o3 : { b: ((...args: any[]) => { c: string; }) | undefined; }
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>c : string | undefined
|
||||
@@ -150,7 +150,7 @@ o3.b?.(1, ...[2, 3], 4).c;
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : readonly [number, number]
|
||||
>[2, 3] : [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -180,7 +180,7 @@ o3.b?.(...[1, 2])["c"];
|
||||
>o3 : { b: ((...args: any[]) => { c: string; }) | undefined; }
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>"c" : "c"
|
||||
@@ -193,7 +193,7 @@ o3.b?.(1, ...[2, 3], 4)["c"];
|
||||
>b : ((...args: any[]) => { c: string; }) | undefined
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : readonly [number, number]
|
||||
>[2, 3] : [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
@@ -223,7 +223,7 @@ o3["b"]?.(...[1, 2]).c;
|
||||
>o3 : { b: ((...args: any[]) => { c: string; }) | undefined; }
|
||||
>"b" : "b"
|
||||
>...[1, 2] : number
|
||||
>[1, 2] : readonly [number, number]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>c : string | undefined
|
||||
@@ -236,7 +236,7 @@ o3["b"]?.(1, ...[2, 3], 4).c;
|
||||
>"b" : "b"
|
||||
>1 : 1
|
||||
>...[2, 3] : number
|
||||
>[2, 3] : readonly [number, number]
|
||||
>[2, 3] : [number, number]
|
||||
>2 : 2
|
||||
>3 : 3
|
||||
>4 : 4
|
||||
|
||||
@@ -269,7 +269,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"] : readonly [number, number, string]
|
||||
>[1, 2, "abc"] : [number, number, string]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>"abc" : "abc"
|
||||
|
||||
@@ -161,7 +161,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"] : readonly [number, number, string]
|
||||
>[1, 2, "abc"] : [number, number, string]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>"abc" : "abc"
|
||||
|
||||
@@ -94,7 +94,7 @@ f2(1, 2, 3, 4, 5, ...[6, 7]);
|
||||
>4 : 4
|
||||
>5 : 5
|
||||
>...[6, 7] : number
|
||||
>[6, 7] : readonly [number, number]
|
||||
>[6, 7] : [number, number]
|
||||
>6 : 6
|
||||
>7 : 7
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ var a = ["./0"];
|
||||
import(...["PathModule"]);
|
||||
>import(...["PathModule"]) : Promise<any>
|
||||
>...["PathModule"] : string
|
||||
>["PathModule"] : readonly [string]
|
||||
>["PathModule"] : [string]
|
||||
>"PathModule" : "PathModule"
|
||||
|
||||
var p1 = import(...a);
|
||||
|
||||
@@ -75,7 +75,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]] : readonly (string | symbol)[]
|
||||
>[...new SymbolIterator, ...[...new _StringIterator]] : (string | symbol)[]
|
||||
>...new SymbolIterator : symbol
|
||||
>new SymbolIterator : SymbolIterator
|
||||
>SymbolIterator : typeof SymbolIterator
|
||||
|
||||
@@ -78,7 +78,7 @@ new Foo(...new SymbolIterator, ...[...new _StringIterator]);
|
||||
>new SymbolIterator : SymbolIterator
|
||||
>SymbolIterator : typeof SymbolIterator
|
||||
>...[...new _StringIterator] : string
|
||||
>[...new _StringIterator] : readonly string[]
|
||||
>[...new _StringIterator] : string[]
|
||||
>...new _StringIterator : string
|
||||
>new _StringIterator : _StringIterator
|
||||
>_StringIterator : typeof _StringIterator
|
||||
|
||||
@@ -1493,7 +1493,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'] : readonly [string, string]
|
||||
>['a', 'x'] : [string, string]
|
||||
>'a' : "a"
|
||||
>'x' : "x"
|
||||
}
|
||||
|
||||
@@ -42,6 +42,6 @@ function foo(set: any) {
|
||||
>values : any
|
||||
>push : any
|
||||
>...[] : never
|
||||
>[] : readonly []
|
||||
>[] : []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -623,7 +623,7 @@ const spreadDynamicImport = import(...[])
|
||||
>spreadDynamicImport : Promise<any>
|
||||
>import(...[]) : Promise<any>
|
||||
>...[] : never
|
||||
>[] : readonly []
|
||||
>[] : []
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ f2(...[],);
|
||||
>f2(...[],) : void
|
||||
>f2 : (...args: any[]) => void
|
||||
>...[] : never
|
||||
>[] : readonly []
|
||||
>[] : []
|
||||
|
||||
// Not confused by overloads
|
||||
declare function f3(x, ): number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
typeParameterConstModifiers.ts(47,14): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
typeParameterConstModifiers.ts(53,9): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
typeParameterConstModifiers.ts(49,14): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
typeParameterConstModifiers.ts(55,9): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
|
||||
|
||||
|
||||
==== typeParameterConstModifiers.ts (2 errors) ====
|
||||
@@ -35,6 +35,8 @@ typeParameterConstModifiers.ts(53,9): error TS1277: 'const' modifier can only ap
|
||||
const x61 = f6(1, 'b', { a: 1, b: 'x' });
|
||||
const x62 = f6(...[1, 'b']);
|
||||
const x63 = f6(true, ...[1, 'b']);
|
||||
const x64 = f6(...([1, 'b']));
|
||||
const x65 = f6(true, ...([1, 'b']));
|
||||
|
||||
class C1<const T> {
|
||||
constructor(x: T) {}
|
||||
|
||||
@@ -33,6 +33,8 @@ 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']);
|
||||
const x64 = f6(...([1, 'b']));
|
||||
const x65 = f6(true, ...([1, 'b']));
|
||||
|
||||
class C1<const T> {
|
||||
constructor(x: T) {}
|
||||
@@ -127,6 +129,8 @@ 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 x64 = f6.apply(void 0, ([1, 'b']));
|
||||
var x65 = f6.apply(void 0, __spreadArray([true], ([1, 'b']), false));
|
||||
var C1 = /** @class */ (function () {
|
||||
function C1(x) {
|
||||
}
|
||||
|
||||
@@ -130,226 +130,234 @@ const x63 = f6(true, ...[1, 'b']);
|
||||
>x63 : Symbol(x63, Decl(typeParameterConstModifiers.ts, 31, 5))
|
||||
>f6 : Symbol(f6, Decl(typeParameterConstModifiers.ts, 25, 61))
|
||||
|
||||
const x64 = f6(...([1, 'b']));
|
||||
>x64 : Symbol(x64, Decl(typeParameterConstModifiers.ts, 32, 5))
|
||||
>f6 : Symbol(f6, Decl(typeParameterConstModifiers.ts, 25, 61))
|
||||
|
||||
const x65 = f6(true, ...([1, 'b']));
|
||||
>x65 : Symbol(x65, Decl(typeParameterConstModifiers.ts, 33, 5))
|
||||
>f6 : Symbol(f6, Decl(typeParameterConstModifiers.ts, 25, 61))
|
||||
|
||||
class C1<const T> {
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 31, 34))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 33, 9))
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 33, 36))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 35, 9))
|
||||
|
||||
constructor(x: T) {}
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 34, 16))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 33, 9))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 36, 16))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 35, 9))
|
||||
|
||||
foo<const U>(x: U) { return x; }
|
||||
>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))
|
||||
>foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 36, 24))
|
||||
>U : Symbol(U, Decl(typeParameterConstModifiers.ts, 37, 8))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 37, 17))
|
||||
>U : Symbol(U, Decl(typeParameterConstModifiers.ts, 37, 8))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 37, 17))
|
||||
}
|
||||
|
||||
const c71 = new C1({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
|
||||
>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))
|
||||
>c71 : Symbol(c71, Decl(typeParameterConstModifiers.ts, 40, 5))
|
||||
>C1 : Symbol(C1, Decl(typeParameterConstModifiers.ts, 33, 36))
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 40, 20))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 40, 26))
|
||||
>d : Symbol(d, Decl(typeParameterConstModifiers.ts, 40, 34))
|
||||
>f : Symbol(f, Decl(typeParameterConstModifiers.ts, 40, 54))
|
||||
|
||||
const c72 = c71.foo(['a', ['b', 'c']]);
|
||||
>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))
|
||||
>c72 : Symbol(c72, Decl(typeParameterConstModifiers.ts, 41, 5))
|
||||
>c71.foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 36, 24))
|
||||
>c71 : Symbol(c71, Decl(typeParameterConstModifiers.ts, 40, 5))
|
||||
>foo : Symbol(C1.foo, Decl(typeParameterConstModifiers.ts, 36, 24))
|
||||
|
||||
const C2 = class <const T> {}
|
||||
>C2 : Symbol(C2, Decl(typeParameterConstModifiers.ts, 41, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 41, 18))
|
||||
>C2 : Symbol(C2, Decl(typeParameterConstModifiers.ts, 43, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 43, 18))
|
||||
|
||||
const fx1 = <const T>(x: T) => x;
|
||||
>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))
|
||||
>fx1 : Symbol(fx1, Decl(typeParameterConstModifiers.ts, 45, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 45, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 45, 22))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 45, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 45, 22))
|
||||
|
||||
const fx2 = <const T,>(x: T) => x;
|
||||
>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))
|
||||
>fx2 : Symbol(fx2, Decl(typeParameterConstModifiers.ts, 46, 5))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 46, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 46, 23))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 46, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 46, 23))
|
||||
|
||||
interface I1<const T> { x: T } // Error
|
||||
>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))
|
||||
>I1 : Symbol(I1, Decl(typeParameterConstModifiers.ts, 46, 34))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 48, 13))
|
||||
>x : Symbol(I1.x, Decl(typeParameterConstModifiers.ts, 48, 23))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 48, 13))
|
||||
|
||||
interface I2 {
|
||||
>I2 : Symbol(I2, Decl(typeParameterConstModifiers.ts, 46, 30))
|
||||
>I2 : Symbol(I2, Decl(typeParameterConstModifiers.ts, 48, 30))
|
||||
|
||||
f<const T>(x: T): T;
|
||||
>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))
|
||||
>f : Symbol(I2.f, Decl(typeParameterConstModifiers.ts, 50, 14))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 51, 6))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 51, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 51, 6))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 51, 6))
|
||||
}
|
||||
|
||||
type T1<const T> = T; // Error
|
||||
>T1 : Symbol(T1, Decl(typeParameterConstModifiers.ts, 50, 1))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 8))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 52, 8))
|
||||
>T1 : Symbol(T1, Decl(typeParameterConstModifiers.ts, 52, 1))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 8))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 54, 8))
|
||||
|
||||
type T2 = <const T>(x: T) => T;
|
||||
>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))
|
||||
>T2 : Symbol(T2, Decl(typeParameterConstModifiers.ts, 54, 21))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 56, 11))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 56, 20))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 56, 11))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 56, 11))
|
||||
|
||||
type T3 = { <const T>(x: T): T };
|
||||
>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))
|
||||
>T3 : Symbol(T3, Decl(typeParameterConstModifiers.ts, 56, 31))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 57, 13))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 57, 22))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 57, 13))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 57, 13))
|
||||
|
||||
type T4 = new <const T>(x: T) => T;
|
||||
>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))
|
||||
>T4 : Symbol(T4, Decl(typeParameterConstModifiers.ts, 57, 33))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 58, 15))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 58, 24))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 58, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 58, 15))
|
||||
|
||||
type T5 = { new <const T>(x: T): T };
|
||||
>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))
|
||||
>T5 : Symbol(T5, Decl(typeParameterConstModifiers.ts, 58, 35))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 59, 17))
|
||||
>x : Symbol(x, Decl(typeParameterConstModifiers.ts, 59, 26))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 59, 17))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 59, 17))
|
||||
|
||||
// Corrected repro from #51745
|
||||
|
||||
type Obj = { a: { b: { c: "123" } } };
|
||||
>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))
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 59, 37))
|
||||
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 63, 12))
|
||||
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 63, 17))
|
||||
>c : Symbol(c, Decl(typeParameterConstModifiers.ts, 63, 22))
|
||||
|
||||
type GetPath<T, P> =
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 61, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 63, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 63, 15))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 63, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 65, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 65, 15))
|
||||
|
||||
P extends readonly [] ? T :
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 63, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 63, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 65, 15))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 65, 13))
|
||||
|
||||
P extends readonly [infer A extends keyof T, ...infer Rest] ? GetPath<T[A], Rest> :
|
||||
>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))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 65, 15))
|
||||
>A : Symbol(A, Decl(typeParameterConstModifiers.ts, 67, 29))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 65, 13))
|
||||
>Rest : Symbol(Rest, Decl(typeParameterConstModifiers.ts, 67, 57))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 63, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 65, 13))
|
||||
>A : Symbol(A, Decl(typeParameterConstModifiers.ts, 67, 29))
|
||||
>Rest : Symbol(Rest, Decl(typeParameterConstModifiers.ts, 67, 57))
|
||||
|
||||
never;
|
||||
|
||||
function set<T, const P extends readonly string[]>(obj: T, path: P, value: GetPath<T, P>) {}
|
||||
>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))
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 68, 10))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 70, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 70, 15))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 70, 51))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 70, 13))
|
||||
>path : Symbol(path, Decl(typeParameterConstModifiers.ts, 70, 58))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 70, 15))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 70, 67))
|
||||
>GetPath : Symbol(GetPath, Decl(typeParameterConstModifiers.ts, 63, 38))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 70, 13))
|
||||
>P : Symbol(P, Decl(typeParameterConstModifiers.ts, 70, 15))
|
||||
|
||||
declare let obj: Obj;
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 70, 11))
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 57, 37))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 72, 11))
|
||||
>Obj : Symbol(Obj, Decl(typeParameterConstModifiers.ts, 59, 37))
|
||||
|
||||
declare let value: "123";
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 71, 11))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 73, 11))
|
||||
|
||||
set(obj, ['a', 'b', 'c'], value);
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 66, 10))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 70, 11))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 71, 11))
|
||||
>set : Symbol(set, Decl(typeParameterConstModifiers.ts, 68, 10))
|
||||
>obj : Symbol(obj, Decl(typeParameterConstModifiers.ts, 72, 11))
|
||||
>value : Symbol(value, Decl(typeParameterConstModifiers.ts, 73, 11))
|
||||
|
||||
// Repro from #52007
|
||||
|
||||
declare function inners<const T extends readonly any[]>(...args: readonly [unknown, ...T, unknown]): T;
|
||||
>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))
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 75, 33))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 79, 24))
|
||||
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 79, 56))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 79, 24))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 79, 24))
|
||||
|
||||
const test = inners(1,2,3,4,5);
|
||||
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 79, 5))
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 73, 33))
|
||||
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 81, 5))
|
||||
>inners : Symbol(inners, Decl(typeParameterConstModifiers.ts, 75, 33))
|
||||
|
||||
declare function inners2<const T extends readonly any[]>(args: readonly [unknown, ...T, unknown]): T;
|
||||
>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))
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 81, 31))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 83, 25))
|
||||
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 83, 57))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 83, 25))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 83, 25))
|
||||
|
||||
const test2 = inners2([1,2,3,4,5]);
|
||||
>test2 : Symbol(test2, Decl(typeParameterConstModifiers.ts, 83, 5))
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 79, 31))
|
||||
>test2 : Symbol(test2, Decl(typeParameterConstModifiers.ts, 85, 5))
|
||||
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 81, 31))
|
||||
|
||||
// Repro from #53307
|
||||
|
||||
type NotEmpty<T extends Record<string, any>> = keyof T extends never ? never : T;
|
||||
>NotEmpty : Symbol(NotEmpty, Decl(typeParameterConstModifiers.ts, 83, 35))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 87, 14))
|
||||
>NotEmpty : Symbol(NotEmpty, Decl(typeParameterConstModifiers.ts, 85, 35))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 89, 14))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 87, 14))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 87, 14))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 89, 14))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 89, 14))
|
||||
|
||||
const thing = <const O extends Record<string, any>>(o: NotEmpty<O>) => o;
|
||||
>thing : Symbol(thing, Decl(typeParameterConstModifiers.ts, 89, 5))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 89, 15))
|
||||
>thing : Symbol(thing, Decl(typeParameterConstModifiers.ts, 91, 5))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 91, 15))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 89, 52))
|
||||
>NotEmpty : Symbol(NotEmpty, Decl(typeParameterConstModifiers.ts, 83, 35))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 89, 15))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 89, 52))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 91, 52))
|
||||
>NotEmpty : Symbol(NotEmpty, Decl(typeParameterConstModifiers.ts, 85, 35))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 91, 15))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 91, 52))
|
||||
|
||||
const t = thing({ foo: '' }); // readonly { foo: "" }
|
||||
>t : Symbol(t, Decl(typeParameterConstModifiers.ts, 91, 5))
|
||||
>thing : Symbol(thing, Decl(typeParameterConstModifiers.ts, 89, 5))
|
||||
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 91, 17))
|
||||
>t : Symbol(t, Decl(typeParameterConstModifiers.ts, 93, 5))
|
||||
>thing : Symbol(thing, Decl(typeParameterConstModifiers.ts, 91, 5))
|
||||
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 93, 17))
|
||||
|
||||
type NotEmptyMapped<T extends Record<string, any>> = keyof T extends never ? never : { [K in keyof T]: T[K] };
|
||||
>NotEmptyMapped : Symbol(NotEmptyMapped, Decl(typeParameterConstModifiers.ts, 91, 29))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
|
||||
>NotEmptyMapped : Symbol(NotEmptyMapped, Decl(typeParameterConstModifiers.ts, 93, 29))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 95, 20))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
|
||||
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 93, 88))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
|
||||
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 93, 88))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 95, 20))
|
||||
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 95, 88))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 95, 20))
|
||||
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 95, 20))
|
||||
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 95, 88))
|
||||
|
||||
const thingMapped = <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o;
|
||||
>thingMapped : Symbol(thingMapped, Decl(typeParameterConstModifiers.ts, 95, 5))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 95, 21))
|
||||
>thingMapped : Symbol(thingMapped, Decl(typeParameterConstModifiers.ts, 97, 5))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 97, 21))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 95, 58))
|
||||
>NotEmptyMapped : Symbol(NotEmptyMapped, Decl(typeParameterConstModifiers.ts, 91, 29))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 95, 21))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 95, 58))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 97, 58))
|
||||
>NotEmptyMapped : Symbol(NotEmptyMapped, Decl(typeParameterConstModifiers.ts, 93, 29))
|
||||
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 97, 21))
|
||||
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 97, 58))
|
||||
|
||||
const tMapped = thingMapped({ foo: '' }); // { foo: "" }
|
||||
>tMapped : Symbol(tMapped, Decl(typeParameterConstModifiers.ts, 97, 5))
|
||||
>thingMapped : Symbol(thingMapped, Decl(typeParameterConstModifiers.ts, 95, 5))
|
||||
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 97, 29))
|
||||
>tMapped : Symbol(tMapped, Decl(typeParameterConstModifiers.ts, 99, 5))
|
||||
>thingMapped : Symbol(thingMapped, Decl(typeParameterConstModifiers.ts, 97, 5))
|
||||
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 99, 29))
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ const x62 = f6(...[1, 'b']);
|
||||
>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, 'b'] : [number, string]
|
||||
>1 : 1
|
||||
>'b' : "b"
|
||||
|
||||
@@ -194,7 +194,28 @@ const x63 = f6(true, ...[1, 'b']);
|
||||
>f6 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>true : true
|
||||
>...[1, 'b'] : string | number
|
||||
>[1, 'b'] : readonly [number, string]
|
||||
>[1, 'b'] : [number, string]
|
||||
>1 : 1
|
||||
>'b' : "b"
|
||||
|
||||
const x64 = f6(...([1, 'b']));
|
||||
>x64 : readonly [number, string]
|
||||
>f6(...([1, 'b'])) : readonly [number, string]
|
||||
>f6 : <const T extends readonly unknown[]>(...args: T) => T
|
||||
>...([1, 'b']) : string | number
|
||||
>([1, 'b']) : [number, string]
|
||||
>[1, 'b'] : [number, string]
|
||||
>1 : 1
|
||||
>'b' : "b"
|
||||
|
||||
const x65 = f6(true, ...([1, 'b']));
|
||||
>x65 : 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']) : [number, string]
|
||||
>[1, 'b'] : [number, string]
|
||||
>1 : 1
|
||||
>'b' : "b"
|
||||
|
||||
|
||||
@@ -7,14 +7,25 @@ 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'])
|
||||
const x23 = f2(...([1, 'foo']))
|
||||
const x24 = 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'])
|
||||
const x33 = f3(...([1, 'foo']))
|
||||
const x34 = f3(true, ...([1, 'foo']))
|
||||
|
||||
declare function f4<const T extends readonly unknown[]>(...args: T): T;
|
||||
const x41 = f4(...[1, 'foo'])
|
||||
const x42 = f4(true, ...[1, 'foo'])
|
||||
const x43 = f4(...([1, 'foo']))
|
||||
const x44 = f4(true, ...([1, 'foo']))
|
||||
|
||||
// dicovered in #52845#issuecomment-1459132562
|
||||
interface IAction {
|
||||
|
||||
+2
@@ -32,6 +32,8 @@ 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']);
|
||||
const x64 = f6(...([1, 'b']));
|
||||
const x65 = f6(true, ...([1, 'b']));
|
||||
|
||||
class C1<const T> {
|
||||
constructor(x: T) {}
|
||||
|
||||
Reference in New Issue
Block a user