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
enumThing{a='a',b='b',};functionf(registrationStatusOptions: SelectOptions<Thing>,onChange: (status: Thing|null)=>void,// <-- Remove the `| null` and the error goes away.): void{select({// <-- Add an explicit type argument `Thing` and the error goes away.options: registrationStatusOptions,onChange: onChange,// ERROR in v5.0.4 but not in v4.9.5: Type '(status: Thing | null) => void' is not assignable to type '(key: string) => void'.});}exportfunctionselect<KeyTextendsstring>(props: SelectProps<KeyT>): void{thrownewError('hello');}exporttypeSelectProps<KeyTextendsstring>={onChange: (key: KeyT)=>void;options?: SelectOptions<KeyT>;// <-- Remove the `?` and the error goes away.};exporttypeSelectOptions<KeyTextendsstring>=// Comment either of the below union members out and the error goes away.|Array<{key: KeyT}>|Array<KeyT>;
π Actual behavior
Got a type error; see "ERROR" comment above. Looks like the type argument to select(...) is being inferred incorrectly.
Minor perturbations of the code cause the error to go away; see other comments above.
This was extracted from some React UI code.
π Expected behavior
TypeScript 4.9.5 infers the type argument I wanted. I was hoping TypeScript 5.0.4 would do the same.
The text was updated successfully, but these errors were encountered:
This is weird since removing the constraint also fixes it. Bisecting.
typeThing='a'|'b';functionf(options: SelectOptions<Thing>,onChange: (status: Thing|null)=>void,// <-- Remove the `| null` and the error goes away.): void{select({// <-- Add an explicit type argument `Thing` and the error goes away.
options,
onChange,// ERROR in v5.0.4 but not in v4.9.5: Type '(status: Thing | null) => void' is not assignable to type '(key: string) => void'.});}declarefunctionselect<KeyTextendsstring>(props: SelectProps<KeyT>): void;typeSelectProps<KeyTextendsstring>={options?: SelectOptions<KeyT>;// <-- Remove the `?` and the error goes away.onChange: (key: KeyT)=>void;};typeSelectOptions<KeyTextendsstring>=// Comment either of the below union members out and the error goes away.|Array<{key: KeyT}>|Array<KeyT>;
Bug Report
π Search Terms
inference string null function parameter
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
select(...)
is being inferred incorrectly.This was extracted from some React UI code.
π Expected behavior
TypeScript 4.9.5 infers the type argument I wanted. I was hoping TypeScript 5.0.4 would do the same.
The text was updated successfully, but these errors were encountered: