From 4f24c80c38c5c34ca4c31be979d88bf8a12f0eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 30 May 2024 09:52:49 +0200 Subject: [PATCH 1/3] Fixed reported errors for variadic element mismatches --- src/compiler/checker.ts | 4 ++-- .../reference/asyncYieldStarContextualType.types | 16 ++++++++-------- .../reference/variadicTuples1.errors.txt | 12 ++++++------ .../reference/variadicTuples2.errors.txt | 4 ++-- .../reference/yieldStarContextualType.types | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7b8d9ad095f11..bd6e32cf88b14 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23412,6 +23412,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const targetArity = getTypeReferenceArity(target); const sourceRestFlag = isTupleType(source) ? source.target.combinedFlags & ElementFlags.Rest : ElementFlags.Rest; const targetRestFlag = target.target.combinedFlags & ElementFlags.Rest; + const targetHasRestElement = target.target.hasRestElement; const sourceMinLength = isTupleType(source) ? source.target.minLength : 0; const targetMinLength = target.target.minLength; if (!sourceRestFlag && sourceArity < targetMinLength) { @@ -23426,7 +23427,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return Ternary.False; } - if (!targetRestFlag && (sourceRestFlag || targetArity < sourceArity)) { + if (!targetHasRestElement && (sourceRestFlag || targetArity < sourceArity)) { if (reportErrors) { if (sourceMinLength < targetMinLength) { reportError(Diagnostics.Target_requires_0_element_s_but_source_may_have_fewer, targetMinLength); @@ -23441,7 +23442,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const targetTypeArguments = getTypeArguments(target); const targetStartCount = getStartElementCount(target.target, ElementFlags.NonRest); const targetEndCount = getEndElementCount(target.target, ElementFlags.NonRest); - const targetHasRestElement = target.target.hasRestElement; let canExcludeDiscriminants = !!excludedProperties; for (let sourcePosition = 0; sourcePosition < sourceArity; sourcePosition++) { const sourceFlags = isTupleType(source) ? source.target.elementFlags[sourcePosition] : ElementFlags.Rest; diff --git a/tests/baselines/reference/asyncYieldStarContextualType.types b/tests/baselines/reference/asyncYieldStarContextualType.types index 0a340b75589ad..55377518eb3e0 100644 --- a/tests/baselines/reference/asyncYieldStarContextualType.types +++ b/tests/baselines/reference/asyncYieldStarContextualType.types @@ -66,13 +66,13 @@ async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookW >authorPromise.then(mapper) : Promise> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >authorPromise.then : , TResult2 = never>(onfulfilled?: (value: Result) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^ ^^^^ ^^ ^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^ >authorPromise : Promise> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >then : , TResult2 = never>(onfulfilled?: (value: Result) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^ ^^^^ ^^ ^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^ >mapper : (result: Result) => Result -> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^ ^^^^^ // With yield*, the type of test2 is // Author | BookWithAuthor @@ -87,13 +87,13 @@ async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookW >authorPromise.then(mapper) : Promise> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >authorPromise.then : , TResult2 = never>(onfulfilled?: (value: Result) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^ ^^^^ ^^ ^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^ >authorPromise : Promise> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >then : , TResult2 = never>(onfulfilled?: (value: Result) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^ ^^^^ ^^ ^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^ >mapper : (result: Result) => Result -> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^ ^^^^^ const x1 = yield* g(); >x1 : unknown @@ -103,7 +103,7 @@ async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookW >g() : AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", unknown, unknown> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >g : () => AsyncGenerator -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^ ^^^^^^^ const x2: number = yield* g(); >x2 : number @@ -113,7 +113,7 @@ async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookW >g() : AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", number, unknown> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >g : () => AsyncGenerator -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^ ^^^^^^^ return null! as BookWithAuthor; >null! as BookWithAuthor : BookWithAuthor diff --git a/tests/baselines/reference/variadicTuples1.errors.txt b/tests/baselines/reference/variadicTuples1.errors.txt index fbc7d599c6ff0..bc68ea7f4476e 100644 --- a/tests/baselines/reference/variadicTuples1.errors.txt +++ b/tests/baselines/reference/variadicTuples1.errors.txt @@ -5,9 +5,9 @@ variadicTuples1.ts(62,5): error TS2345: Argument of type '[]' is not assignable variadicTuples1.ts(131,9): error TS2344: Type 'V' does not satisfy the constraint 'unknown[]'. The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type 'unknown[]'. variadicTuples1.ts(149,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...T]'. - Target requires 2 element(s) but source may have fewer. + Source provides no match for variadic element at position 1 in target. variadicTuples1.ts(151,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...U]'. - Target requires 2 element(s) but source may have fewer. + Source provides no match for variadic element at position 1 in target. variadicTuples1.ts(152,5): error TS2322: Type '[string, ...T]' is not assignable to type '[string, ...U]'. Type at position 1 in source is not compatible with type at position 1 in target. Type 'T' is not assignable to type 'U'. @@ -22,7 +22,7 @@ variadicTuples1.ts(170,5): error TS2322: Type 'T' is not assignable to type '[.. variadicTuples1.ts(171,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'. variadicTuples1.ts(181,5): error TS2322: Type 'T' is not assignable to type '[...U]'. Type 'string[]' is not assignable to type '[...U]'. - Target requires 1 element(s) but source may have fewer. + Source provides no match for variadic element at position 0 in target. variadicTuples1.ts(182,5): error TS2322: Type '[...T]' is not assignable to type '[...U]'. Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'string[]'. @@ -211,12 +211,12 @@ variadicTuples1.ts(411,7): error TS2322: Type '[boolean, false]' is not assignab y = x; // Error ~ !!! error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...T]'. -!!! error TS2322: Target requires 2 element(s) but source may have fewer. +!!! error TS2322: Source provides no match for variadic element at position 1 in target. y = z; z = x; // Error ~ !!! error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...U]'. -!!! error TS2322: Target requires 2 element(s) but source may have fewer. +!!! error TS2322: Source provides no match for variadic element at position 1 in target. z = y; // Error ~ !!! error TS2322: Type '[string, ...T]' is not assignable to type '[string, ...U]'. @@ -268,7 +268,7 @@ variadicTuples1.ts(411,7): error TS2322: Type '[boolean, false]' is not assignab ~~ !!! error TS2322: Type 'T' is not assignable to type '[...U]'. !!! error TS2322: Type 'string[]' is not assignable to type '[...U]'. -!!! error TS2322: Target requires 1 element(s) but source may have fewer. +!!! error TS2322: Source provides no match for variadic element at position 0 in target. t2 = t1; // Error ~~ !!! error TS2322: Type '[...T]' is not assignable to type '[...U]'. diff --git a/tests/baselines/reference/variadicTuples2.errors.txt b/tests/baselines/reference/variadicTuples2.errors.txt index 9ae0ed7c394e3..269771a5f2691 100644 --- a/tests/baselines/reference/variadicTuples2.errors.txt +++ b/tests/baselines/reference/variadicTuples2.errors.txt @@ -38,7 +38,7 @@ variadicTuples2.ts(73,8): error TS2345: Argument of type '["abc", "def", true]' variadicTuples2.ts(76,5): error TS2322: Type '[number, number]' is not assignable to type '[number, ...T]'. Source provides no match for variadic element at position 1 in target. variadicTuples2.ts(77,5): error TS2322: Type '[number, ...number[]]' is not assignable to type '[number, ...T]'. - Target requires 2 element(s) but source may have fewer. + Source provides no match for variadic element at position 1 in target. variadicTuples2.ts(78,5): error TS2322: Type '[number, ...T]' is not assignable to type '[number, number]'. Type '[number, ...unknown[]]' is not assignable to type '[number, number]'. Target requires 2 element(s) but source may have fewer. @@ -208,7 +208,7 @@ variadicTuples2.ts(139,25): error TS2345: Argument of type '["blah2", 1, 2, 3]' x = z; // Error ~ !!! error TS2322: Type '[number, ...number[]]' is not assignable to type '[number, ...T]'. -!!! error TS2322: Target requires 2 element(s) but source may have fewer. +!!! error TS2322: Source provides no match for variadic element at position 1 in target. y = x; // Error ~ !!! error TS2322: Type '[number, ...T]' is not assignable to type '[number, number]'. diff --git a/tests/baselines/reference/yieldStarContextualType.types b/tests/baselines/reference/yieldStarContextualType.types index 08f89242fda8c..a3996cf7981ef 100644 --- a/tests/baselines/reference/yieldStarContextualType.types +++ b/tests/baselines/reference/yieldStarContextualType.types @@ -17,7 +17,7 @@ function* f(): Generator { >g() : Generator > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >g : () => Generator -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^ ^^^^^^^ const x2: number = yield* g(); >x2 : number @@ -27,5 +27,5 @@ function* f(): Generator { >g() : Generator > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >g : () => Generator -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^ ^^^^^^^ } From 4b315552433e52e965171859b38ba9fd6dd693af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 30 May 2024 10:03:20 +0200 Subject: [PATCH 2/3] adjust the other condition --- src/compiler/checker.ts | 3 +- .../reference/variadicTuples3.errors.txt | 35 +++++++++++++ .../reference/variadicTuples3.symbols | 47 +++++++++++++++++ .../baselines/reference/variadicTuples3.types | 50 +++++++++++++++++++ .../types/tuple/variadicTuples3.ts | 19 +++++++ 5 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/variadicTuples3.errors.txt create mode 100644 tests/baselines/reference/variadicTuples3.symbols create mode 100644 tests/baselines/reference/variadicTuples3.types create mode 100644 tests/cases/conformance/types/tuple/variadicTuples3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bd6e32cf88b14..0ffcc55b7f7d8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23411,7 +23411,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const sourceArity = getTypeReferenceArity(source); const targetArity = getTypeReferenceArity(target); const sourceRestFlag = isTupleType(source) ? source.target.combinedFlags & ElementFlags.Rest : ElementFlags.Rest; - const targetRestFlag = target.target.combinedFlags & ElementFlags.Rest; const targetHasRestElement = target.target.hasRestElement; const sourceMinLength = isTupleType(source) ? source.target.minLength : 0; const targetMinLength = target.target.minLength; @@ -23421,7 +23420,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return Ternary.False; } - if (!targetRestFlag && targetArity < sourceMinLength) { + if (!targetHasRestElement && targetArity < sourceMinLength) { if (reportErrors) { reportError(Diagnostics.Source_has_0_element_s_but_target_allows_only_1, sourceMinLength, targetArity); } diff --git a/tests/baselines/reference/variadicTuples3.errors.txt b/tests/baselines/reference/variadicTuples3.errors.txt new file mode 100644 index 0000000000000..34b62aecf6dc0 --- /dev/null +++ b/tests/baselines/reference/variadicTuples3.errors.txt @@ -0,0 +1,35 @@ +variadicTuples3.ts(5,3): error TS2322: Type 'any[]' is not assignable to type '[...T, ...P]'. + Source provides no match for variadic element at position 0 in target. +variadicTuples3.ts(10,3): error TS2322: Type '[any, any]' is not assignable to type '[...T, ...P]'. + Source provides no match for variadic element at position 0 in target. +variadicTuples3.ts(15,3): error TS2322: Type '[any, any, any]' is not assignable to type '[...T, ...P]'. + Source provides no match for variadic element at position 0 in target. + + +==== variadicTuples3.ts (3 errors) ==== + // https://github.com/microsoft/TypeScript/issues/58697 + + function test1(): [...T, ...P] { + let x: any[] = []; + return x; + ~~~~~~ +!!! error TS2322: Type 'any[]' is not assignable to type '[...T, ...P]'. +!!! error TS2322: Source provides no match for variadic element at position 0 in target. + } + + function test2(): [...T, ...P] { + let x: [any, any] = [null, null]; + return x; + ~~~~~~ +!!! error TS2322: Type '[any, any]' is not assignable to type '[...T, ...P]'. +!!! error TS2322: Source provides no match for variadic element at position 0 in target. + } + + function test3(): [...T, ...P] { + let x: [any, any, any] = [null, null, null]; + return x; + ~~~~~~ +!!! error TS2322: Type '[any, any, any]' is not assignable to type '[...T, ...P]'. +!!! error TS2322: Source provides no match for variadic element at position 0 in target. + } + \ No newline at end of file diff --git a/tests/baselines/reference/variadicTuples3.symbols b/tests/baselines/reference/variadicTuples3.symbols new file mode 100644 index 0000000000000..ed8c60440519c --- /dev/null +++ b/tests/baselines/reference/variadicTuples3.symbols @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/types/tuple/variadicTuples3.ts] //// + +=== variadicTuples3.ts === +// https://github.com/microsoft/TypeScript/issues/58697 + +function test1(): [...T, ...P] { +>test1 : Symbol(test1, Decl(variadicTuples3.ts, 0, 0)) +>T : Symbol(T, Decl(variadicTuples3.ts, 2, 15)) +>P : Symbol(P, Decl(variadicTuples3.ts, 2, 31)) +>T : Symbol(T, Decl(variadicTuples3.ts, 2, 15)) +>P : Symbol(P, Decl(variadicTuples3.ts, 2, 31)) + + let x: any[] = []; +>x : Symbol(x, Decl(variadicTuples3.ts, 3, 5)) + + return x; +>x : Symbol(x, Decl(variadicTuples3.ts, 3, 5)) +} + +function test2(): [...T, ...P] { +>test2 : Symbol(test2, Decl(variadicTuples3.ts, 5, 1)) +>T : Symbol(T, Decl(variadicTuples3.ts, 7, 15)) +>P : Symbol(P, Decl(variadicTuples3.ts, 7, 31)) +>T : Symbol(T, Decl(variadicTuples3.ts, 7, 15)) +>P : Symbol(P, Decl(variadicTuples3.ts, 7, 31)) + + let x: [any, any] = [null, null]; +>x : Symbol(x, Decl(variadicTuples3.ts, 8, 5)) + + return x; +>x : Symbol(x, Decl(variadicTuples3.ts, 8, 5)) +} + +function test3(): [...T, ...P] { +>test3 : Symbol(test3, Decl(variadicTuples3.ts, 10, 1)) +>T : Symbol(T, Decl(variadicTuples3.ts, 12, 15)) +>P : Symbol(P, Decl(variadicTuples3.ts, 12, 31)) +>T : Symbol(T, Decl(variadicTuples3.ts, 12, 15)) +>P : Symbol(P, Decl(variadicTuples3.ts, 12, 31)) + + let x: [any, any, any] = [null, null, null]; +>x : Symbol(x, Decl(variadicTuples3.ts, 13, 5)) + + return x; +>x : Symbol(x, Decl(variadicTuples3.ts, 13, 5)) +} + diff --git a/tests/baselines/reference/variadicTuples3.types b/tests/baselines/reference/variadicTuples3.types new file mode 100644 index 0000000000000..303507d764c71 --- /dev/null +++ b/tests/baselines/reference/variadicTuples3.types @@ -0,0 +1,50 @@ +//// [tests/cases/conformance/types/tuple/variadicTuples3.ts] //// + +=== variadicTuples3.ts === +// https://github.com/microsoft/TypeScript/issues/58697 + +function test1(): [...T, ...P] { +>test1 : () => [...T, ...P] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ + + let x: any[] = []; +>x : any[] +> : ^^^^^ +>[] : never[] +> : ^^^^^^^ + + return x; +>x : any[] +> : ^^^^^ +} + +function test2(): [...T, ...P] { +>test2 : () => [...T, ...P] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ + + let x: [any, any] = [null, null]; +>x : [any, any] +> : ^^^^^^^^^^ +>[null, null] : [null, null] +> : ^^^^^^^^^^^^ + + return x; +>x : [any, any] +> : ^^^^^^^^^^ +} + +function test3(): [...T, ...P] { +>test3 : () => [...T, ...P] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ + + let x: [any, any, any] = [null, null, null]; +>x : [any, any, any] +> : ^^^^^^^^^^^^^^^ +>[null, null, null] : [null, null, null] +> : ^^^^^^^^^^^^^^^^^^ + + return x; +>x : [any, any, any] +> : ^^^^^^^^^^^^^^^ +} + diff --git a/tests/cases/conformance/types/tuple/variadicTuples3.ts b/tests/cases/conformance/types/tuple/variadicTuples3.ts new file mode 100644 index 0000000000000..40478e3ea6b08 --- /dev/null +++ b/tests/cases/conformance/types/tuple/variadicTuples3.ts @@ -0,0 +1,19 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/58697 + +function test1(): [...T, ...P] { + let x: any[] = []; + return x; +} + +function test2(): [...T, ...P] { + let x: [any, any] = [null, null]; + return x; +} + +function test3(): [...T, ...P] { + let x: [any, any, any] = [null, null, null]; + return x; +} From e251a9d42020fb7410e845d6380e8c515a0f53d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 14 Jun 2024 21:12:10 +0200 Subject: [PATCH 3/3] Avoid using `hasRestElement` --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b9df056f4f32d..5d67431022a1e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23665,7 +23665,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const sourceArity = getTypeReferenceArity(source); const targetArity = getTypeReferenceArity(target); const sourceRestFlag = isTupleType(source) ? source.target.combinedFlags & ElementFlags.Rest : ElementFlags.Rest; - const targetHasRestElement = target.target.hasRestElement; + const targetHasRestElement = !!(target.target.combinedFlags & ElementFlags.Variable); const sourceMinLength = isTupleType(source) ? source.target.minLength : 0; const targetMinLength = target.target.minLength; if (!sourceRestFlag && sourceArity < targetMinLength) {