2 ms·
How to type-check JavaScript with the function x()
- galaxyLogic 4y agoA small fix: if ( v.constructor === T) { return x; } should really better be: if ( v !== null && v !== undefined && v.constructor === T) { return x; } The purposes of x() is to throw an error under specific circumstances, and the original version does that. But when we do v.constructor if v is undefined or null and 'maybe;' is falsy then it throws an error but the message is obscure since it is caused by trying to get the constructor of undefined or null.