Closed
Description
Bug Report
π Search Terms
conditional types, 2339
π Version & Regression Information
- This changed between versions 4.8.4 and 4.93
- This bug also occurs on nightly version 5.0.0-dev.20221121
β― Playground Link
Playground link with relevant code and test cases
π» Code
// Errors in TS 4.9.3 but not in 4.8.4
interface A {}
type B = A extends Record<'foo', string> ? A['foo'] : string; // Error: Property 'foo' does not exist on type 'A'.(2339)
// Succeeds in TS 4.9.3 and 4.8.4
interface C { foo: number; }
type D = C extends Record<'foo', string> ? C['foo'] : string; // Correct: string
// Succeeds in TS 4.9.3 and 4.8.4
interface E { foo: string; }
type F = E extends Record<'foo', string> ? E['foo'] : string; // Correct: string
// Succeeds in TS 4.9.3 and 4.8.4
interface G { foo: 'bar'; }
type H = G extends Record<'foo', string> ? G['foo'] : string; // Correct: 'bar'
π Actual behavior
interface A {}
type B = A extends Record<'foo', string> ? A['foo'] : string;
errors with 2339: Property 'foo' does not exist on type 'A'.
This change causes @vuejs/pinia to fail as one can see in vuejs/pinia#1814
π Expected behavior
interface A {}
type B = A extends Record<'foo', string> ? A['foo'] : string;
returns with B
being an alias for type string
.