BugDomain: Conditional TypesHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
Index signature assignability, generic index signatures, conditional types
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types
⯠Playground Link
Playground link with relevant code
ð» Code
// Use of the conditional type `string extends T` prevents assignability.
// However, the conditional type `T extends string` is accepted.
declare class Foo<T> {
bar: string extends T ? number : boolean;
}
declare let indexable: Foo<{[key: string]: boolean}>;
declare let namedProp: Foo<{baz: boolean}>;
indexable = namedProp;
ð Actual behavior
When a conditional type is present in Foo, I sometimes cannot assign Foo<{a: any}> to Foo<[x: string]: any>, depending on the condition.
ð Expected behavior
Regardless of the conditional type, I should be able to assign Foo with named properties to Foo with an index signature.