You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeLoadable<TValue>=|{state: "loading"}|{state: "complete"value: TValue}functionmapLoadable<TValue>(loadable: Loadable<TValue>,map: (value: TValue)=>void): void{}typeAugmentedLoadable=|{state: "loading"value: number}|{state: "complete"value: string}functionmapAugmented(augmented: AugmentedLoadable){mapLoadable(augmented,()=>{})// β Errors with "Argument of type 'AugmentedLoadable' is not assignable to parameter of type 'Loadable<number>'"mapLoadable<string>(augmented,()=>{})// β Works now that type is generic is specified}
π Actual behavior
TypeScript incorrectly infers that augmented should be assignable to Loadable<number> rather than a Loadable<string>, because we've added an unrelated value: number property to it. It can be nudged into working by writing out the generic type.
π Expected behavior
TypeScript to infer the correct generic of string.
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
discrimated union generic extra property
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
TypeScript incorrectly infers that
augmented
should be assignable toLoadable<number>
rather than aLoadable<string>
, because we've added an unrelatedvalue: number
property to it. It can be nudged into working by writing out the generic type.π Expected behavior
TypeScript to infer the correct generic of
string
.The text was updated successfully, but these errors were encountered: