π Search Terms
partial record mapped type generic constraint
π Version & Regression Information
- This changed between versions 3.9.7 and 4.0.5
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.3#code/C4TwDgpgBA6g9gJwNYGcA8AVKEAewIB2AJilHAEYBWEAxsADRQCq2ehJUA3lANoDSUAJYEoSCCDgAzKBgC6AfgBcUAIYEQUAL4A+KAF5mAbgBQoSFABiKwQBt0WXPmKkK1OoxaP2pAAoqEwIIqNmgASrSIRGhiEtIYjGog2sn6Rsam4NAAggBCqZwqyijACMIA5ozkisWlBGWaGeZ5BpxVUDXlDcYA9N0yABYQKNDkcMD9UADuiEiqxNgAbsEArir4UMBwG4PtKgC20GYQjdAYQ8DwyCgAjKmXqGi5jDnaJzLnVrY3qZ92jznPV49PoAOS2EAQCEQKDeZ2K9xQACZMKwnBxcroDAjMIDgVAAKKQxDKDCZKAAchy5KgRDgQygBDGu0CKEkGnG0BocAINWsBGAFL8ASCIXCXIQURiUhkCXUyXJADpYR9rHZkQ42M4oBifqr7LigA
π» Code
type Works<T extends object, U extends { [K in keyof T]?: any }> = U;
type Fails<T extends object, U extends Partial<Record<keyof T, any>>> = U;
type AB = {a: string, b:string}
type B = {b: string}
// These both work and evaluate to the same type
type TestWorks1 = Works<AB, B>
type TestFails1 = Fails<AB, B>
// No errors
type TestWorks2<T extends AB> = Works<T, B>
// Error: Type 'B' does not satisfy the constraint 'Partial<Record<keyof T, any>>'.
type TestFails2<T extends AB> = Fails<T, B>
π Actual behavior
Works and Fails behave differently
TestFails2 results in an error
π Expected behavior
Works and Fails behave the same
TestFails2 does not result in an error
Additional information about the issue
easrng (@easrng) narrowed down the divergence in behavior between the two types to this line in checker.ts (screenshot because the file is too big for github to display):

π Search Terms
partial record mapped type generic constraint
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.3#code/C4TwDgpgBA6g9gJwNYGcA8AVKEAewIB2AJilHAEYBWEAxsADRQCq2ehJUA3lANoDSUAJYEoSCCDgAzKBgC6AfgBcUAIYEQUAL4A+KAF5mAbgBQoSFABiKwQBt0WXPmKkK1OoxaP2pAAoqEwIIqNmgASrSIRGhiEtIYjGog2sn6Rsam4NAAggBCqZwqyijACMIA5ozkisWlBGWaGeZ5BpxVUDXlDcYA9N0yABYQKNDkcMD9UADuiEiqxNgAbsEArir4UMBwG4PtKgC20GYQjdAYQ8DwyCgAjKmXqGi5jDnaJzLnVrY3qZ92jznPV49PoAOS2EAQCEQKDeZ2K9xQACZMKwnBxcroDAjMIDgVAAKKQxDKDCZKAAchy5KgRDgQygBDGu0CKEkGnG0BocAINWsBGAFL8ASCIXCXIQURiUhkCXUyXJADpYR9rHZkQ42M4oBifqr7LigA
π» Code
π Actual behavior
WorksandFailsbehave differentlyTestFails2results in an errorπ Expected behavior
WorksandFailsbehave the sameTestFails2does not result in an errorAdditional information about the issue
easrng (@easrng) narrowed down the divergence in behavior between the two types to this line in checker.ts (screenshot because the file is too big for github to display):