mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 07:55:10 -05:00
Merge pull request #28718 from Microsoft/fixDefinitelyAssignableRelation
Fix definitely assignable relation
This commit is contained in:
@@ -12259,7 +12259,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)) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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]
|
||||
@@ -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;
|
||||
}>;
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user