The TypeScript documentation says that
The
never
type is a subtype of, and assignable to, every type
but doesn\'t m
You are not calling the useNever
function. If you try to call it with a parameter it will fail since a value can not be never
. But as always, you can trick the compiler with typeguards e.g. this will work
const test = (val: string | number) => {
if (typeof val === "string") {
} else if (typeof val === "number") {
} else {
useNever(val); // works, since val is not number or string it is implicitly never
}
}