diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 073c0d46d7b4e..ee8b72d303487 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25115,7 +25115,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isReadonlySymbol(sourceProp) !== isReadonlySymbol(targetProp)) { return Ternary.False; } - return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); + return compareTypes(getNonMissingTypeOfSymbol(sourceProp), getNonMissingTypeOfSymbol(targetProp)); } function isMatchingSignature(source: Signature, target: Signature, partialMatch: boolean) { diff --git a/tests/baselines/reference/exactOptionalPropertyTypesIdentical.errors.txt b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.errors.txt new file mode 100644 index 0000000000000..8ed639135a13f --- /dev/null +++ b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.errors.txt @@ -0,0 +1,15 @@ +exactOptionalPropertyTypesIdentical.ts(2,12): error TS2322: Type '() => T extends { a?: string; } ? 0 : 1' is not assignable to type '() => T extends { a?: string | undefined; } ? 0 : 1'. + Type 'T extends { a?: string; } ? 0 : 1' is not assignable to type 'T extends { a?: string | undefined; } ? 0 : 1'. + Type '0 | 1' is not assignable to type 'T extends { a?: string | undefined; } ? 0 : 1'. + Type '0' is not assignable to type 'T extends { a?: string | undefined; } ? 0 : 1'. + + +==== exactOptionalPropertyTypesIdentical.ts (1 errors) ==== + export let a: () => T extends {a?: string} ? 0 : 1 = null!; + export let b: () => T extends {a?: string | undefined} ? 0 : 1 = a; + ~ +!!! error TS2322: Type '() => T extends { a?: string; } ? 0 : 1' is not assignable to type '() => T extends { a?: string | undefined; } ? 0 : 1'. +!!! error TS2322: Type 'T extends { a?: string; } ? 0 : 1' is not assignable to type 'T extends { a?: string | undefined; } ? 0 : 1'. +!!! error TS2322: Type '0 | 1' is not assignable to type 'T extends { a?: string | undefined; } ? 0 : 1'. +!!! error TS2322: Type '0' is not assignable to type 'T extends { a?: string | undefined; } ? 0 : 1'. + \ No newline at end of file diff --git a/tests/baselines/reference/exactOptionalPropertyTypesIdentical.js b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.js new file mode 100644 index 0000000000000..e3153ce591e35 --- /dev/null +++ b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts] //// + +//// [exactOptionalPropertyTypesIdentical.ts] +export let a: () => T extends {a?: string} ? 0 : 1 = null!; +export let b: () => T extends {a?: string | undefined} ? 0 : 1 = a; + + +//// [exactOptionalPropertyTypesIdentical.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = exports.a; diff --git a/tests/baselines/reference/exactOptionalPropertyTypesIdentical.symbols b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.symbols new file mode 100644 index 0000000000000..e7bbad247053d --- /dev/null +++ b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts] //// + +=== exactOptionalPropertyTypesIdentical.ts === +export let a: () => T extends {a?: string} ? 0 : 1 = null!; +>a : Symbol(a, Decl(exactOptionalPropertyTypesIdentical.ts, 0, 10)) +>T : Symbol(T, Decl(exactOptionalPropertyTypesIdentical.ts, 0, 15)) +>T : Symbol(T, Decl(exactOptionalPropertyTypesIdentical.ts, 0, 15)) +>a : Symbol(a, Decl(exactOptionalPropertyTypesIdentical.ts, 0, 34)) + +export let b: () => T extends {a?: string | undefined} ? 0 : 1 = a; +>b : Symbol(b, Decl(exactOptionalPropertyTypesIdentical.ts, 1, 10)) +>T : Symbol(T, Decl(exactOptionalPropertyTypesIdentical.ts, 1, 15)) +>T : Symbol(T, Decl(exactOptionalPropertyTypesIdentical.ts, 1, 15)) +>a : Symbol(a, Decl(exactOptionalPropertyTypesIdentical.ts, 1, 34)) +>a : Symbol(a, Decl(exactOptionalPropertyTypesIdentical.ts, 0, 10)) + diff --git a/tests/baselines/reference/exactOptionalPropertyTypesIdentical.types b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.types new file mode 100644 index 0000000000000..ff2ea9358fd9b --- /dev/null +++ b/tests/baselines/reference/exactOptionalPropertyTypesIdentical.types @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts] //// + +=== exactOptionalPropertyTypesIdentical.ts === +export let a: () => T extends {a?: string} ? 0 : 1 = null!; +>a : () => T extends { a?: string; } ? 0 : 1 +> : ^ ^^^^^^^ +>a : string | undefined +> : ^^^^^^^^^^^^^^^^^^ +>null! : never +> : ^^^^^ + +export let b: () => T extends {a?: string | undefined} ? 0 : 1 = a; +>b : () => T extends { a?: string | undefined; } ? 0 : 1 +> : ^ ^^^^^^^ +>a : string | undefined +> : ^^^^^^^^^^^^^^^^^^ +>a : () => T extends { a?: string; } ? 0 : 1 +> : ^ ^^^^^^^ + diff --git a/tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts b/tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts new file mode 100644 index 0000000000000..3abb2bc66b2c9 --- /dev/null +++ b/tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts @@ -0,0 +1,5 @@ +// @strictNullChecks: true +// @exactOptionalPropertyTypes: true + +export let a: () => T extends {a?: string} ? 0 : 1 = null!; +export let b: () => T extends {a?: string | undefined} ? 0 : 1 = a;