Is there a way to erase, forbid, omit the bottom type any
from being passed into a function or in other contexts? I know there's the analysis like listing avoiding implicit any
s that can be done but there's times where that can still fail in a mixed code base.
// suppose this `any` comes from somewhere else and lints ok
const someValue: any = 27;
// now I have this function
function superFunction(x: number) {
// magic
}
// now with `any` I can call it because `any` spoils the type system.
superFunction(someValue);
// this still works from a type-checking scenario
const someValue2: any = {};
superFunction(someValue2); // Runtime error!
I would expect there's some sort of generic helper like Pick
, Omit
, etc. that would force the caller to do its own assertions. Something like this
type NeverAny<T> = // erase `any`ness
function superFunction(x: NeverAny<number>) {
// magic
}
const someValue: any = 27;
const someValue2: any = {};
superFunction(someValue); // Type-checking time: "Any is forbidden here"
superFunction(someValue2); // Type-checking time: "Any is forbidden here"