Skip to content
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

Fix definitely assignable relation #28718

Merged
merged 3 commits into from
Nov 29, 2018
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
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12254,7 +12254,8 @@ namespace ts {
else if (target.flags & TypeFlags.IndexedAccess) {
// A type S is related to a type T[K], where T and K aren't both type variables, if S is related to C,
// where C is the base constraint of T[K]
if (relation !== identityRelation && !(isGenericObjectType((<IndexedAccessType>target).objectType) && isGenericIndexType((<IndexedAccessType>target).indexType))) {
if (relation !== identityRelation && relation !== definitelyAssignableRelation &&
!(isGenericObjectType((<IndexedAccessType>target).objectType) && isGenericIndexType((<IndexedAccessType>target).indexType))) {
const constraint = getBaseConstraintOfType(target);
if (constraint && constraint !== target) {
if (result = isRelatedTo(source, constraint, reportErrors)) {
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/conditionalTypes2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,13 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2

type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;

// Repro from #28654

type MaybeTrue<T extends { b: boolean }> = true extends T["b"] ? "yes" : "no";

type T0 = MaybeTrue<{ b: never }> // "no"
type T1 = MaybeTrue<{ b: false }>; // "no"
type T2 = MaybeTrue<{ b: true }>; // "yes"
type T3 = MaybeTrue<{ b: boolean }>; // "yes"

24 changes: 24 additions & 0 deletions tests/baselines/reference/conditionalTypes2.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ type B2<T, V> =

type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;

// Repro from #28654

type MaybeTrue<T extends { b: boolean }> = true extends T["b"] ? "yes" : "no";

type T0 = MaybeTrue<{ b: never }> // "no"
type T1 = MaybeTrue<{ b: false }>; // "no"
type T2 = MaybeTrue<{ b: true }>; // "yes"
type T3 = MaybeTrue<{ b: boolean }>; // "yes"


//// [conditionalTypes2.js]
Expand Down Expand Up @@ -304,3 +313,18 @@ declare type B2<T, V> = T extends object ? T extends any[] ? T : {
declare type C2<T, V, E> = T extends object ? {
[Q in keyof T]: C2<T[Q], V, E>;
} : T;
declare type MaybeTrue<T extends {
b: boolean;
}> = true extends T["b"] ? "yes" : "no";
declare type T0 = MaybeTrue<{
b: never;
}>;
declare type T1 = MaybeTrue<{
b: false;
}>;
declare type T2 = MaybeTrue<{
b: true;
}>;
declare type T3 = MaybeTrue<{
b: boolean;
}>;
28 changes: 28 additions & 0 deletions tests/baselines/reference/conditionalTypes2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,31 @@ type C2<T, V, E> =
>E : Symbol(E, Decl(conditionalTypes2.ts, 144, 13))
>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8))

// Repro from #28654

type MaybeTrue<T extends { b: boolean }> = true extends T["b"] ? "yes" : "no";
>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63))
>T : Symbol(T, Decl(conditionalTypes2.ts, 149, 15))
>b : Symbol(b, Decl(conditionalTypes2.ts, 149, 26))
>T : Symbol(T, Decl(conditionalTypes2.ts, 149, 15))

type T0 = MaybeTrue<{ b: never }> // "no"
>T0 : Symbol(T0, Decl(conditionalTypes2.ts, 149, 78))
>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63))
>b : Symbol(b, Decl(conditionalTypes2.ts, 151, 21))

type T1 = MaybeTrue<{ b: false }>; // "no"
>T1 : Symbol(T1, Decl(conditionalTypes2.ts, 151, 33))
>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63))
>b : Symbol(b, Decl(conditionalTypes2.ts, 152, 21))

type T2 = MaybeTrue<{ b: true }>; // "yes"
>T2 : Symbol(T2, Decl(conditionalTypes2.ts, 152, 34))
>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63))
>b : Symbol(b, Decl(conditionalTypes2.ts, 153, 21))

type T3 = MaybeTrue<{ b: boolean }>; // "yes"
>T3 : Symbol(T3, Decl(conditionalTypes2.ts, 153, 33))
>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63))
>b : Symbol(b, Decl(conditionalTypes2.ts, 154, 21))

25 changes: 25 additions & 0 deletions tests/baselines/reference/conditionalTypes2.types
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,28 @@ type C2<T, V, E> =

T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;

// Repro from #28654

type MaybeTrue<T extends { b: boolean }> = true extends T["b"] ? "yes" : "no";
>MaybeTrue : MaybeTrue<T>
>b : boolean
>true : true

type T0 = MaybeTrue<{ b: never }> // "no"
>T0 : "no"
>b : never

type T1 = MaybeTrue<{ b: false }>; // "no"
>T1 : "no"
>b : false
>false : false

type T2 = MaybeTrue<{ b: true }>; // "yes"
>T2 : "yes"
>b : true
>true : true

type T3 = MaybeTrue<{ b: boolean }>; // "yes"
>T3 : "yes"
>b : boolean

Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ type B2<T, V> =

type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;

// Repro from #28654

type MaybeTrue<T extends { b: boolean }> = true extends T["b"] ? "yes" : "no";

type T0 = MaybeTrue<{ b: never }> // "no"
type T1 = MaybeTrue<{ b: false }>; // "no"
type T2 = MaybeTrue<{ b: true }>; // "yes"
type T3 = MaybeTrue<{ b: boolean }>; // "yes"