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
Posted question to StackOverflow: Generic React/Typescript function has function in props but does not detect return type when param added but it occurs to me this may be a bug!?
Playground link with relevant code
function simplified<T>(props: { generator: () => T, receiver: (t: T) => any }) { } function whatIWant<T>(props: { generator: (bob: any) => T, receiver: (t: T) => any }) { } function nonObject<T>(generator: (bob: any) => T, receiver: (t: T) => any) { } simplified({ generator: () => 123, receiver: (t) => console.log(t + 2) }) whatIWant({ generator: (bob) => bob ? 1 : 2, receiver: (t) => console.log(t + 2) }) nonObject((bob) => bob ? 1 : 2, (t) => console.log(t + 2))
The whatIWant function is showing an error because it thinks t is unknown type.
whatIWant
t
unknown
The other two (simplified and nonObject are correctly seeing t as a number type.
simplified
nonObject
number
Above code (all three cases) should have no errors.
I'm particularly confused by the difference between simplified and whatIWant. Why is this correct behaviour, or is it a bug?
The text was updated successfully, but these errors were encountered:
See #47599
Sorry, something went wrong.
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Successfully merging a pull request may close this issue.
Bug Report
🔎 Search Terms
Posted question to StackOverflow:
Generic React/Typescript function has function in props but does not detect return type when param added
but it occurs to me this may be a bug!?
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The
whatIWant
function is showing an error because it thinkst
isunknown
type.The other two (
simplified
andnonObject
are correctly seeingt
as anumber
type.🙂 Expected behavior
Above code (all three cases) should have no errors.
I'm particularly confused by the difference between
simplified
andwhatIWant
. Why is this correct behaviour, or is it a bug?The text was updated successfully, but these errors were encountered: