Skip to content
Permalink
Browse files
Forward intersection state flag to conditional type target check (#50620
)
  • Loading branch information
andrewbranch committed Sep 7, 2022
1 parent b58721f commit bb6f36f7c80c290b98759823445dae73ebfd3eb2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
@@ -19821,8 +19821,8 @@ namespace ts {
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
const skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType));
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
if (result = skipTrue ? Ternary.True : isRelatedTo(source, getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false)) {
result &= skipFalse ? Ternary.True : isRelatedTo(source, getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false);
if (result = skipTrue ? Ternary.True : isRelatedTo(source, getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
result &= skipFalse ? Ternary.True : isRelatedTo(source, getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
if (result) {
return result;
}
@@ -0,0 +1,10 @@
//// [excessPropertyCheckingIntersectionWithConditional.ts]
type Foo<K> = K extends unknown ? { a: number } : unknown
const createDefaultExample = <K,>(x: K): Foo<K> & { x: K; } => {
return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2
}

//// [excessPropertyCheckingIntersectionWithConditional.js]
var createDefaultExample = function (x) {
return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2
};
@@ -0,0 +1,22 @@
=== tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts ===
type Foo<K> = K extends unknown ? { a: number } : unknown
>Foo : Symbol(Foo, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 0))
>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 9))
>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 9))
>a : Symbol(a, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 35))

const createDefaultExample = <K,>(x: K): Foo<K> & { x: K; } => {
>createDefaultExample : Symbol(createDefaultExample, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 5))
>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30))
>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 34))
>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30))
>Foo : Symbol(Foo, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 0))
>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30))
>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 51))
>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30))

return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2
>a : Symbol(a, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 2, 10))
>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 2, 16))
>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 34))
}
@@ -0,0 +1,18 @@
=== tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts ===
type Foo<K> = K extends unknown ? { a: number } : unknown
>Foo : Foo<K>
>a : number

const createDefaultExample = <K,>(x: K): Foo<K> & { x: K; } => {
>createDefaultExample : <K>(x: K) => Foo<K> & { x: K; }
><K,>(x: K): Foo<K> & { x: K; } => { return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2} : <K>(x: K) => Foo<K> & { x: K; }
>x : K
>x : K

return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2
>{ a: 1, x: x } : { a: number; x: K; }
>a : number
>1 : 1
>x : K
>x : K
}
@@ -0,0 +1,4 @@
type Foo<K> = K extends unknown ? { a: number } : unknown
const createDefaultExample = <K,>(x: K): Foo<K> & { x: K; } => {
return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2
}

0 comments on commit bb6f36f

Please sign in to comment.