6 ms·
Is there a way to say a variable can hold any type - eg for a log or print function.
by ape4 5y ago
Is there a way to say a variable can hold any type - eg for a log or print function.
- kevingadd 5y agoThat's the default
- Ndymium 5y agoTypeScript itself has two types for this purpose: "any" and "unknown". "any" is the escape hatch and allows you to do anything with the variable. In essence it stops type checking entirely for that variable. "unknown" takes the opposite approach and doesn't let you do anything with the variable value (other than pass it along to other "unknown" accepting variables/functions) until you have asserted its actual type with type guards.