New issue
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 accepts wrong code inferring unknown #48624
Comments
This is all expected behavior; I don't see any demonstration of a defect here (aside: just calling something nonsense doesn't help me explain where the disconnect is)
In the |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Linked examples contain also other compiling code like: /**
* computed type is:
* const nonsense1: (a: unknown) => (b: unknown) => string
*/
const nonsense1 = curry(() => "test"); Allowing me to I guess TS allows to pass almost any function as function argument, irregardless of its arity by design. declare function tstx(fn: (a: string) => number):number
//compiles
tstx(() => 1) The parameter types for |
Yes, this is addressed in the FAQ and is the intended behavior |
"functions with fewer parameters assignable to functions that take more parameters" Thank you for your explanation. |
It should be noted that "functions with fewer parameters assignable to functions that take more parameters" |
Bug Report
🔎 Search Terms
searched:
is:issue is:open label:Bug ts(2345)
is:issue is:open label:Docs ts(2345)
🕗 Version & Regression Information
Tested with 4.6.3 and 4.5.2.
Please keep and fill in the line that best applies:
⏯ Playground Link
Playground link with relevant code
💻 Code
Hi, I wanted to share these examples. I could not find a similar ticket.
This is a compilation issue.
I have encountered several cases where a nonsensical code compiles.
Most of these examples have something in common, they all have
unknown
somewherein the type.
For example this compiles:
It is important to note that
unknown
can easily hide behind a narrower type, e.g.Here is a file with more examples (some made playground upset):
https://github.com/rpeszek/typescript-issues/blob/master/src/AcceptingWrongCode/IncorrectlyAcceptingUnknown.ts
These examples are also described in my blog series about TS types (Part 1 and 4):
https://rpeszek.github.io/tags/TypeScript-Notes.html
🙁 Actual behavior
Nonsensical code compiles
🙂 Expected behavior
Nonsensical code should not compile
The text was updated successfully, but these errors were encountered: