How to Use the never Type for a Function That Never Returns in TypeScript
Write : never on a function that always throws, and TypeScript knows the code after a call to it only runs when the call didn’t happen.
- Programming
- TypeScript
Write : never on a function that always throws, and TypeScript knows the code after a call to it only runs when the call didn’t happen.
Write a type in angle brackets after a generic type’s name, such as Array, and tsc only lets values of that type in.
Write type in front of an imported type, so a tool that removes the types removes the import too.
Write a colon and a type after the parameter’s name, and tsc reports any call that passes the wrong kind of value.