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
declarefunctionproduce(f: NoInfer<()=>void>): ()=>void;declarefunctionproduce<A>(f: NoInfer<(arg: A)=>void>): (arg: A)=>void;constx: ()=>void=produce(()=>1);// worksconsty: (arg: string)=>void=produce((v)=>1);// Parameter 'v' implicitly has an 'any' type.
π Actual behavior
Because const y is explicitly typed and thanks to the new utility NoInfer type, the compiler is able to figure out (from the return type) it is calling the produce<string>() overload. (Without NoInfer it would just be produce<any>()).
However, apparently it does not apply this knowledge to the function parameter f and thus the non type-hinted argument v is inferred as any
π Expected behavior
Since the compiler already knows f is of type NoInfer<(arg:string)=>void> it should be able to infer the lambda argument v to be of string type.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
NoInfer, overload
π Version & Regression Information
Version 5.4.3
β― Playground Link
https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwAcYdhkwQAKRALngDkcBJVREGAHgoEp4BeAPngA3HFmD8utbn0EixAbgBQoSLAQp02PIWKly7AIL8qtBs1YcKsAOa0DPAcNHjJ8KzFvx7MpwsWKwPABnDHgADykHWWc+HRIySmlHAEYuJUDUEPgATykbWhCYLFRrKN9gWKJ48goKITLUpSA
π» Code
π Actual behavior
Because
const y
is explicitly typed and thanks to the new utilityNoInfer
type, the compiler is able to figure out (from the return type) it is calling theproduce<string>()
overload. (WithoutNoInfer
it would just beproduce<any>()
).However, apparently it does not apply this knowledge to the function parameter
f
and thus the non type-hinted argumentv
is inferred asany
π Expected behavior
Since the compiler already knows
f
is of typeNoInfer<(arg:string)=>void>
it should be able to infer the lambda argumentv
to be ofstring
type.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: