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
const test3 = (cb: (arg1: string) => void) => {
cb("test")
}
const test2 = (cb: () => void) => {
test3(cb)
}
const test = () => {
test2((val?: number) => {
console.log(typeof val) // Expect number but it prints string
})
}
test()
🙁 Actual behavior
This type checks just fine and prints out "string"
🙂 Expected behavior
This should fail somehow because it is unsound. I'm not sure where it should fail and maybe this is just an accepted bug, but if that is the case then the FAQ should be updated to reflect that you can make unsound behavior by implicitly casting functions with optional parameters.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
optional argument cast callback
🕗 Version & Regression Information
There is a FAQ for half of this bug https://github.com./Microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
This type checks just fine and prints out "string"
🙂 Expected behavior
This should fail somehow because it is unsound. I'm not sure where it should fail and maybe this is just an accepted bug, but if that is the case then the FAQ should be updated to reflect that you can make unsound behavior by implicitly casting functions with optional parameters.
The text was updated successfully, but these errors were encountered: