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

This commit is contained in:
Hans Brende 2025-09-30 15:15:38 -05:00 committed by GitHub
parent d4b15eb56d
commit 31a0ead46d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 69 additions and 1 deletions

View File

@ -25273,7 +25273,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) {

View File

@ -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'.

View File

@ -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;

View File

@ -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))

View File

@ -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
> : ^ ^^^^^^^

View File

@ -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;