6 ms·
Definitely not a TS expert but I think it’s for cases where you know something “better” than it is known to the type system. An example that pops to mind is ho
by dmitryminkovsky 5y ago
Definitely not a TS expert but I think it’s for cases where you know something “better” than it is known to the type system.
An example that pops to mind is how React’s createContext() typings for some reason require a non-bill default value, but you may not have such a value at the time the call is made. Personally I think it’s totally legit to just do createContext<T>(null!). I don’t think this leads to errors that won’t get quickly noticed.
But if you get carried away, it’ll bite you for sure, especially in code that has more going on than define a React context.