I'm pretty sure it's not possible but I'm hoping I'm wrong. I want to throw an error message that says something like "expected number, received string", but for a function that uses generics. Something like this:
function makeData<T>(data: T, priority: number) {
if (data === null || data === undefined) {
throw new Error(`TypeError: variable "data" is invalid. Expected ${T}`);
}
// ...
}
I would also be happy to learn another way to type this function, such that passing null or undefined to this it will make TypeScript flag it as an error (currently it does just fine for other data types just not these two).
Thanks!