-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix conditional type type parameter leak (#31455)
* Fix conditional type type parameter leak * Monkey with comment text per code review * Conditionally clone type param * Reuse input array and avoid making mapper where possible
- Loading branch information
Showing
6 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/conditionalDoesntLeakUninstantiatedTypeParameter.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
tests/cases/compiler/conditionalDoesntLeakUninstantiatedTypeParameter.ts(7,7): error TS2322: Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/conditionalDoesntLeakUninstantiatedTypeParameter.ts (1 errors) ==== | ||
interface Synthetic<A, B extends A> {} | ||
type SyntheticDestination<T, U> = U extends Synthetic<T, infer V> ? V : never; | ||
type TestSynthetic = // Resolved to T, should be `number` or an inference failure (`unknown`) | ||
SyntheticDestination<number, Synthetic<number, number>>; | ||
|
||
const y: TestSynthetic = 3; // Type '3' is not assignable to type 'T'. (shouldn't error) | ||
const z: TestSynthetic = '3'; // Type '"3""' is not assignable to type 'T'. (should not mention T) | ||
~ | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/conditionalDoesntLeakUninstantiatedTypeParameter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [conditionalDoesntLeakUninstantiatedTypeParameter.ts] | ||
interface Synthetic<A, B extends A> {} | ||
type SyntheticDestination<T, U> = U extends Synthetic<T, infer V> ? V : never; | ||
type TestSynthetic = // Resolved to T, should be `number` or an inference failure (`unknown`) | ||
SyntheticDestination<number, Synthetic<number, number>>; | ||
|
||
const y: TestSynthetic = 3; // Type '3' is not assignable to type 'T'. (shouldn't error) | ||
const z: TestSynthetic = '3'; // Type '"3""' is not assignable to type 'T'. (should not mention T) | ||
|
||
|
||
//// [conditionalDoesntLeakUninstantiatedTypeParameter.js] | ||
var y = 3; // Type '3' is not assignable to type 'T'. (shouldn't error) | ||
var z = '3'; // Type '"3""' is not assignable to type 'T'. (should not mention T) |
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/conditionalDoesntLeakUninstantiatedTypeParameter.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/compiler/conditionalDoesntLeakUninstantiatedTypeParameter.ts === | ||
interface Synthetic<A, B extends A> {} | ||
>Synthetic : Symbol(Synthetic, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 0)) | ||
>A : Symbol(A, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 20)) | ||
>B : Symbol(B, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 22)) | ||
>A : Symbol(A, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 20)) | ||
|
||
type SyntheticDestination<T, U> = U extends Synthetic<T, infer V> ? V : never; | ||
>SyntheticDestination : Symbol(SyntheticDestination, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 38)) | ||
>T : Symbol(T, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 26)) | ||
>U : Symbol(U, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 28)) | ||
>U : Symbol(U, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 28)) | ||
>Synthetic : Symbol(Synthetic, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 0)) | ||
>T : Symbol(T, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 26)) | ||
>V : Symbol(V, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 62)) | ||
>V : Symbol(V, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 62)) | ||
|
||
type TestSynthetic = // Resolved to T, should be `number` or an inference failure (`unknown`) | ||
>TestSynthetic : Symbol(TestSynthetic, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 78)) | ||
|
||
SyntheticDestination<number, Synthetic<number, number>>; | ||
>SyntheticDestination : Symbol(SyntheticDestination, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 38)) | ||
>Synthetic : Symbol(Synthetic, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 0, 0)) | ||
|
||
const y: TestSynthetic = 3; // Type '3' is not assignable to type 'T'. (shouldn't error) | ||
>y : Symbol(y, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 5, 5)) | ||
>TestSynthetic : Symbol(TestSynthetic, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 78)) | ||
|
||
const z: TestSynthetic = '3'; // Type '"3""' is not assignable to type 'T'. (should not mention T) | ||
>z : Symbol(z, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 6, 5)) | ||
>TestSynthetic : Symbol(TestSynthetic, Decl(conditionalDoesntLeakUninstantiatedTypeParameter.ts, 1, 78)) | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/conditionalDoesntLeakUninstantiatedTypeParameter.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=== tests/cases/compiler/conditionalDoesntLeakUninstantiatedTypeParameter.ts === | ||
interface Synthetic<A, B extends A> {} | ||
type SyntheticDestination<T, U> = U extends Synthetic<T, infer V> ? V : never; | ||
>SyntheticDestination : SyntheticDestination<T, U> | ||
|
||
type TestSynthetic = // Resolved to T, should be `number` or an inference failure (`unknown`) | ||
>TestSynthetic : number | ||
|
||
SyntheticDestination<number, Synthetic<number, number>>; | ||
|
||
const y: TestSynthetic = 3; // Type '3' is not assignable to type 'T'. (shouldn't error) | ||
>y : number | ||
>3 : 3 | ||
|
||
const z: TestSynthetic = '3'; // Type '"3""' is not assignable to type 'T'. (should not mention T) | ||
>z : number | ||
>'3' : "3" | ||
|
7 changes: 7 additions & 0 deletions
7
tests/cases/compiler/conditionalDoesntLeakUninstantiatedTypeParameter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface Synthetic<A, B extends A> {} | ||
type SyntheticDestination<T, U> = U extends Synthetic<T, infer V> ? V : never; | ||
type TestSynthetic = // Resolved to T, should be `number` or an inference failure (`unknown`) | ||
SyntheticDestination<number, Synthetic<number, number>>; | ||
|
||
const y: TestSynthetic = 3; // Type '3' is not assignable to type 'T'. (shouldn't error) | ||
const z: TestSynthetic = '3'; // Type '"3""' is not assignable to type 'T'. (should not mention T) |