diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a457944e027a7..f80c4c07ee45c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; } diff --git a/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.js b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.js new file mode 100644 index 0000000000000..971053105ca0a --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.js @@ -0,0 +1,10 @@ +//// [excessPropertyCheckingIntersectionWithConditional.ts] +type Foo = K extends unknown ? { a: number } : unknown +const createDefaultExample = (x: K): Foo & { 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 +}; diff --git a/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.symbols b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.symbols new file mode 100644 index 0000000000000..aca3252c77402 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts === +type Foo = 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 = (x: K): Foo & { 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)) +} diff --git a/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.types b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.types new file mode 100644 index 0000000000000..5d2ec637e8da2 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts === +type Foo = K extends unknown ? { a: number } : unknown +>Foo : Foo +>a : number + +const createDefaultExample = (x: K): Foo & { x: K; } => { +>createDefaultExample : (x: K) => Foo & { x: K; } +>(x: K): Foo & { x: K; } => { return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2} : (x: K) => Foo & { 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 +} diff --git a/tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts b/tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts new file mode 100644 index 0000000000000..c0e25cd85454e --- /dev/null +++ b/tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts @@ -0,0 +1,4 @@ +type Foo = K extends unknown ? { a: number } : unknown +const createDefaultExample = (x: K): Foo & { x: K; } => { + return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2 +} \ No newline at end of file