Skip to content

Fix conditional type resolution #29338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 68 additions & 66 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3916,7 +3916,9 @@ namespace ts {
aliasTypeArguments?: ReadonlyArray<Type>; // Alias type arguments (if any)
/* @internal */ aliasTypeArgumentsContainsMarker?: boolean; // Alias type arguments (if any)
/* @internal */
wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
permissiveInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
/* @internal */
restrictiveInstantiation?: Type; // Instantiation with type parameters mapped to unconstrained form
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should permissiveInstantiations and restrictiveInstantiations have pointers back to the original type, this way when we attempt to get them, if we already have one of them we can avoid bothering instantiating a new type (and often creating a new type identity)?

/* @internal */
immediateBaseConstraint?: Type; // Immediate base constraint cache
}
Expand Down
8 changes: 8 additions & 0 deletions tests/baselines/reference/conditionalTypes1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,12 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS

var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})

// Repros from #23843

type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;

type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;

10 changes: 10 additions & 0 deletions tests/baselines/reference/conditionalTypes1.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ declare function assign<T>(o: T, a: RecursivePartial<T>): void;

var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})

// Repros from #23843

type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;

type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;


//// [conditionalTypes1.js]
Expand Down Expand Up @@ -715,3 +723,5 @@ declare var a: {
c: string;
}[];
};
declare type Weird1 = (<U extends boolean>(a: U) => never) extends (<U extends true>(a: U) => never) ? never : never;
declare type Weird2 = (<U extends boolean>(a: U) => U) extends (<U extends true>(a: U) => infer T) ? T : never;
27 changes: 27 additions & 0 deletions tests/baselines/reference/conditionalTypes1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,30 @@ assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
>a : Symbol(a, Decl(conditionalTypes1.ts, 351, 25))
>c : Symbol(c, Decl(conditionalTypes1.ts, 351, 30))

// Repros from #23843

type Weird1 = (<U extends boolean>(a: U) => never) extends
>Weird1 : Symbol(Weird1, Decl(conditionalTypes1.ts, 351, 46))
>U : Symbol(U, Decl(conditionalTypes1.ts, 355, 16))
>a : Symbol(a, Decl(conditionalTypes1.ts, 355, 35))
>U : Symbol(U, Decl(conditionalTypes1.ts, 355, 16))

(<U extends true>(a: U) => never) ? never : never;
>U : Symbol(U, Decl(conditionalTypes1.ts, 356, 6))
>a : Symbol(a, Decl(conditionalTypes1.ts, 356, 22))
>U : Symbol(U, Decl(conditionalTypes1.ts, 356, 6))

type Weird2 = (<U extends boolean>(a: U) => U) extends
>Weird2 : Symbol(Weird2, Decl(conditionalTypes1.ts, 356, 54))
>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16))
>a : Symbol(a, Decl(conditionalTypes1.ts, 358, 35))
>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16))
>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16))

(<U extends true>(a: U) => infer T) ? T : never;
>U : Symbol(U, Decl(conditionalTypes1.ts, 359, 6))
>a : Symbol(a, Decl(conditionalTypes1.ts, 359, 22))
>U : Symbol(U, Decl(conditionalTypes1.ts, 359, 6))
>T : Symbol(T, Decl(conditionalTypes1.ts, 359, 36))
>T : Symbol(T, Decl(conditionalTypes1.ts, 359, 36))

18 changes: 18 additions & 0 deletions tests/baselines/reference/conditionalTypes1.types
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,21 @@ assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
>c : string
>'213123' : "213123"

// Repros from #23843

type Weird1 = (<U extends boolean>(a: U) => never) extends
>Weird1 : never
>a : U

(<U extends true>(a: U) => never) ? never : never;
>true : true
>a : U

type Weird2 = (<U extends boolean>(a: U) => U) extends
>Weird2 : boolean
>a : U

(<U extends true>(a: U) => infer T) ? T : never;
>true : true
>a : U

Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,11 @@ declare function assign<T>(o: T, a: RecursivePartial<T>): void;

var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})

// Repros from #23843

type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;

type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;