We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Version: 3.7.x-dev.201xxxxx 3.7.4
Search Terms: inference
function func(arg: {foo:1, bar: 1}) {} // 1. Fails giveMeAFunc(func) // 2. Succeeds giveMeAFunc<{foo: 1, bar: 1}, typeof func>(func) function giveMeAFunc<TArg extends {foo:1}, TFn extends (t:TArg) => void>(fn:TFn) {}
Expected behavior: I'd expect TS to infer the type arguments in case 1 (to be case 2)
Actual behavior: Fails with message that bar is a missing property
bar
Playground Link: Couldn't find a "Share" button
Related Issues: not really
The text was updated successfully, but these errors were encountered:
I should probably add another comment:
Why not just type giveMeAFunc like this then?
giveMeAFunc
function giveMeAFunc<TArg extends {foo:1}>(fn:(t:TArg) => void) {}
While that works, I want to use the exact type of the function for parts of the return type in my real world example. Something like
function giveMeAFunc<TArg extends {foo:1}, TFn extends (t:TArg) => void>(fn:TFn):TFn { return null as any }
Sorry, something went wrong.
That said - I realized that this works
function giveMeAFunc<TArg extends {foo:1}, TFn>(fn:TFn & ((t:TArg) => void)):TFn { return null as any }
Why? And also, isn't the original issue still valid?
See #30134.
Ultimately you have "too many" type parameters and this is not the best way to write the function declaration.
@RyanCavanaugh ok, thanks. Is there a better way, that allows me to:
foo
?
Not really, since what you're describing is both an upper and lower bound on the function. The intersection you have is the best option.
No branches or pull requests
TypeScript Version: 3.7.x-dev.201xxxxx
3.7.4
Search Terms:
inference
Expected behavior:
I'd expect TS to infer the type arguments in case 1 (to be case 2)
Actual behavior:
Fails with message that
bar
is a missing propertyPlayground Link:
Couldn't find a "Share" button
Related Issues:
not really
The text was updated successfully, but these errors were encountered: