-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Passing never type as a function parameter does not fail type check #56952
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
Comments
|
OK, understood -- but is there a reason it doesn't work a bit more like |
I'm not sure what rule you're proposing. At best, you'd introduce many different inconsistencies where higher-order and zero-order forms disagreed about validity. |
I'm arguing from a 'principle of least surprise' angle. If I try to pass a My proposal is there would be some setting similar to Is there a real world example where someone would actually want to be able to pass or return a never? |
Sure, you might have something like this declare function myRoundingFunc(n: number): number;
declare function doSomething(value: number, ifEven: () => string, ifOdd: () => string, ifFractional: () => string): string;
// Input from somewhere
declare let n: number
n = myRoundingFunc(n);
const p = doSomething(n, () => "n is even", () => "n is odd", () => { throw new Error("This can't happen") });
console.log(p); |
|
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
never parameter argument
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/FAMwrgdgxgLglgewgAhAhAKARgQwE7IBcyAzjHnBAOYCUyA3sMslEiQgDYCmAdBwlWz4aAbmABfYKEixEKKlxgA5LgDcueDHWIQ1Ghk2QwAFngQB3ZLssBRPGc0ADJQgAOXR6IlS0mBcr1NGlEgA
π» Code
π Actual behavior
No type errors
π Expected behavior
Type error: can not pass type never to function foo
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: