Skip to content

Don't compare "missing" to undefined in compareProperties under exactOptionalPropertyTypes #61683

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exactOptionalPropertyTypesIdentical.ts(2,12): error TS2322: Type '<T>() => T extends { a?: string; } ? 0 : 1' is not assignable to type '<T>() => 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>() => T extends {a?: string} ? 0 : 1 = null!;
export let b: <T>() => T extends {a?: string | undefined} ? 0 : 1 = a;
~
!!! error TS2322: Type '<T>() => T extends { a?: string; } ? 0 : 1' is not assignable to type '<T>() => 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'.

13 changes: 13 additions & 0 deletions tests/baselines/reference/exactOptionalPropertyTypesIdentical.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts] ////

//// [exactOptionalPropertyTypesIdentical.ts]
export let a: <T>() => T extends {a?: string} ? 0 : 1 = null!;
export let b: <T>() => 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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts] ////

=== exactOptionalPropertyTypesIdentical.ts ===
export let a: <T>() => 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>() => 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))

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts] ////

=== exactOptionalPropertyTypesIdentical.ts ===
export let a: <T>() => T extends {a?: string} ? 0 : 1 = null!;
>a : <T>() => T extends { a?: string; } ? 0 : 1
> : ^ ^^^^^^^
>a : string | undefined
> : ^^^^^^^^^^^^^^^^^^
>null! : never
> : ^^^^^

export let b: <T>() => T extends {a?: string | undefined} ? 0 : 1 = a;
>b : <T>() => T extends { a?: string | undefined; } ? 0 : 1
> : ^ ^^^^^^^
>a : string | undefined
> : ^^^^^^^^^^^^^^^^^^
>a : <T>() => T extends { a?: string; } ? 0 : 1
> : ^ ^^^^^^^

5 changes: 5 additions & 0 deletions tests/cases/compiler/exactOptionalPropertyTypesIdentical.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @strictNullChecks: true
// @exactOptionalPropertyTypes: true

export let a: <T>() => T extends {a?: string} ? 0 : 1 = null!;
export let b: <T>() => T extends {a?: string | undefined} ? 0 : 1 = a;