Skip to content

Commit 579e494

Browse files
authored
Preserve partially typed tuple names in more places (microsoft#55789)
1 parent 758884c commit 579e494

File tree

7 files changed

+61
-10
lines changed

7 files changed

+61
-10
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33356,8 +33356,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3335633356
if (arg.kind === SyntaxKind.SyntheticExpression && (arg as SyntheticExpression).tupleNameSource) {
3335733357
names.push((arg as SyntheticExpression).tupleNameSource!);
3335833358
}
33359+
else {
33360+
names.push(undefined);
33361+
}
3335933362
}
33360-
return createTupleType(types, flags, inConstContext && !someType(restType, isMutableArrayLikeType), length(names) === length(types) ? names : undefined);
33363+
return createTupleType(types, flags, inConstContext && !someType(restType, isMutableArrayLikeType), names);
3336133364
}
3336233365

3336333366
function checkTypeArguments(signature: Signature, typeArgumentNodes: readonly TypeNode[], reportErrors: boolean, headMessage?: DiagnosticMessage): Type[] | undefined {
@@ -35741,12 +35744,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3574135744
types.push(restType);
3574235745
flags.push(ElementFlags.Variadic);
3574335746
}
35744-
const name = getNameableDeclarationAtPosition(source, i);
35745-
if (name) {
35746-
names.push(name);
35747-
}
35747+
names.push(getNameableDeclarationAtPosition(source, i));
3574835748
}
35749-
return createTupleType(types, flags, readonly, length(names) === length(types) ? names : undefined);
35749+
return createTupleType(types, flags, readonly, names);
3575035750
}
3575135751

3575235752
// Return the number of parameters in a signature. The rest parameter, if present, counts as one

tests/baselines/reference/argumentsReferenceInFunction1_Js.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
index.js(1,25): error TS7006: Parameter 'f' implicitly has an 'any' type.
2-
index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, ...any[]]'.
2+
index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any, ...any[]]'.
33

44

55
==== index.js (2 errors) ====
@@ -19,6 +19,6 @@ index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable t
1919
const debuglog = function() {
2020
return format.apply(null, arguments);
2121
~~~~~~~~~
22-
!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, ...any[]]'.
22+
!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any, ...any[]]'.
2323
};
2424

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/conformance/types/tuple/named/partiallyNamedTuples3.ts] ////
2+
3+
//// [partiallyNamedTuples3.ts]
4+
declare const tuple: [number, name: string, boolean, value: number, string];
5+
6+
const output = ((...args) => args)(...tuple);
7+
8+
9+
//// [partiallyNamedTuples3.js]
10+
"use strict";
11+
var output = (function () {
12+
var args = [];
13+
for (var _i = 0; _i < arguments.length; _i++) {
14+
args[_i] = arguments[_i];
15+
}
16+
return args;
17+
}).apply(void 0, tuple);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/conformance/types/tuple/named/partiallyNamedTuples3.ts] ////
2+
3+
=== partiallyNamedTuples3.ts ===
4+
declare const tuple: [number, name: string, boolean, value: number, string];
5+
>tuple : Symbol(tuple, Decl(partiallyNamedTuples3.ts, 0, 13))
6+
7+
const output = ((...args) => args)(...tuple);
8+
>output : Symbol(output, Decl(partiallyNamedTuples3.ts, 2, 5))
9+
>args : Symbol(args, Decl(partiallyNamedTuples3.ts, 2, 17))
10+
>args : Symbol(args, Decl(partiallyNamedTuples3.ts, 2, 17))
11+
>tuple : Symbol(tuple, Decl(partiallyNamedTuples3.ts, 0, 13))
12+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/conformance/types/tuple/named/partiallyNamedTuples3.ts] ////
2+
3+
=== partiallyNamedTuples3.ts ===
4+
declare const tuple: [number, name: string, boolean, value: number, string];
5+
>tuple : [number, name: string, boolean, value: number, string]
6+
7+
const output = ((...args) => args)(...tuple);
8+
>output : [number, name: string, boolean, value: number, string]
9+
>((...args) => args)(...tuple) : [number, name: string, boolean, value: number, string]
10+
>((...args) => args) : (args_0: number, name: string, args_2: boolean, value: number, args_4: string) => [number, name: string, boolean, value: number, string]
11+
>(...args) => args : (args_0: number, name: string, args_2: boolean, value: number, args_4: string) => [number, name: string, boolean, value: number, string]
12+
>args : [number, name: string, boolean, value: number, string]
13+
>args : [number, name: string, boolean, value: number, string]
14+
>...tuple : string | number | boolean
15+
>tuple : [number, name: string, boolean, value: number, string]
16+

tests/baselines/reference/restTuplesFromContextualTypes.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ f3((a, b, c) => {})
265265
f3((...x) => {})
266266
>f3((...x) => {}) : void
267267
>f3 : (cb: (x: number, args_0: boolean, ...args_1: string[]) => void) => void
268-
>(...x) => {} : (x_0: number, x_1: boolean, ...x_2: string[]) => void
269-
>x : [number, boolean, ...string[]]
268+
>(...x) => {} : (x: number, x_1: boolean, ...x_2: string[]) => void
269+
>x : [x: number, boolean, ...string[]]
270270

271271
f3((a, ...x) => {})
272272
>f3((a, ...x) => {}) : void
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @strict: true
2+
// @lib: esnext
3+
4+
declare const tuple: [number, name: string, boolean, value: number, string];
5+
6+
const output = ((...args) => args)(...tuple);

0 commit comments

Comments
 (0)