forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'generic-cfa' into generic-guard
- Loading branch information
Showing
12 changed files
with
427 additions
and
43 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
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.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,20 @@ | ||
tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts(9,5): error TS2322: Type 'Stuff<U>' is not assignable to type 'Stuff<T>'. | ||
Type 'U' is not assignable to type 'T'. | ||
'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. | ||
|
||
|
||
==== tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
p1 = p2; // Error | ||
~~ | ||
!!! error TS2322: Type 'Stuff<U>' is not assignable to type 'Stuff<T>'. | ||
!!! error TS2322: Type 'U' is not assignable to type 'T'. | ||
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.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,17 @@ | ||
//// [conditionalTypeVarianceBigArrayConstraintsPerformance.ts] | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
p1 = p2; // Error | ||
} | ||
|
||
//// [conditionalTypeVarianceBigArrayConstraintsPerformance.js] | ||
/// <reference path="react16.d.ts" /> | ||
function F(p1, p2) { | ||
p1 = p2; // Error | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.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,34 @@ | ||
=== tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
>Stuff : Symbol(Stuff, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 0, 0)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 2, 11)) | ||
|
||
T extends keyof JSX.IntrinsicElements | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 2, 11)) | ||
>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) | ||
>IntrinsicElements : Symbol(JSX.IntrinsicElements, Decl(react16.d.ts, 2514, 86)) | ||
|
||
? JSX.IntrinsicElements[T] | ||
>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) | ||
>IntrinsicElements : Symbol(JSX.IntrinsicElements, Decl(react16.d.ts, 2514, 86)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 2, 11)) | ||
|
||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
>F : Symbol(F, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 5, 14)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 11)) | ||
>U : Symbol(U, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 13)) | ||
>p1 : Symbol(p1, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 17)) | ||
>Stuff : Symbol(Stuff, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 0, 0)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 11)) | ||
>p2 : Symbol(p2, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 30)) | ||
>Stuff : Symbol(Stuff, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 0, 0)) | ||
>U : Symbol(U, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 13)) | ||
|
||
p1 = p2; // Error | ||
>p1 : Symbol(p1, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 17)) | ||
>p2 : Symbol(p2, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 30)) | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.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,24 @@ | ||
=== tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
>Stuff : Stuff<T> | ||
|
||
T extends keyof JSX.IntrinsicElements | ||
>JSX : any | ||
|
||
? JSX.IntrinsicElements[T] | ||
>JSX : any | ||
|
||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
>F : <T, U>(p1: Stuff<T>, p2: Stuff<U>) => void | ||
>p1 : Stuff<T> | ||
>p2 : Stuff<U> | ||
|
||
p1 = p2; // Error | ||
>p1 = p2 : Stuff<U> | ||
>p1 : Stuff<T> | ||
>p2 : Stuff<U> | ||
} |
54 changes: 54 additions & 0 deletions
54
.../reference/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.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,54 @@ | ||
tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts(13,5): error TS2322: Type 'ReturnType<T[M]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<T[keyof T]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<T[string | number | symbol]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<T[string]> | ReturnType<T[number]> | ReturnType<T[symbol]>' is not assignable to type 'A'. | ||
Type 'ReturnType<T[number]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<FunctionsObj<T>[number]>' is not assignable to type 'A'. | ||
Property 'x' is missing in type '{}' but required in type 'A'. | ||
|
||
|
||
==== tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts (1 errors) ==== | ||
interface A { x: number } | ||
|
||
declare function isA(a: unknown): a is A; | ||
|
||
type FunctionsObj<T> = { | ||
[K in keyof T]: () => unknown | ||
} | ||
|
||
function g< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>, x: A) { | ||
x = a2; | ||
~ | ||
!!! error TS2322: Type 'ReturnType<T[M]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[keyof T]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[string | number | symbol]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[string]> | ReturnType<T[number]> | ReturnType<T[symbol]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[number]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<FunctionsObj<T>[number]>' is not assignable to type 'A'. | ||
!!! error TS2322: Property 'x' is missing in type '{}' but required in type 'A'. | ||
!!! related TS2728 tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts:1:15: 'x' is declared here. | ||
} | ||
|
||
// Original CFA report of the above issue | ||
|
||
function g2< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>) { | ||
if (isA(a2)) { | ||
// a2 is not narrowed | ||
a2.x // error, but should be ok | ||
} | ||
} | ||
|
Oops, something went wrong.