How can I handle unwanted TypeScript checks related to JavaScript usage in today's development environment?
Consider the following function:
function connect(config: string): void {
// Getting warning for the line that follows:
// typeof check is always false: 'config' always has type 'string'
if (typeof config !== 'string') {
throw new Error('Connection config must be a string');
}
// execute normally...
}
I am using WebStorm UI, which displays warnings in certain situations. However, these warnings are irrelevant because the module is ultimately compiled into JavaScript and distributed in that format. The validation is primarily for calls from JavaScript clients, with potential TypeScript clients in mind as well. Changing the function parameter type to any
in the declaration is not an ideal solution.
What is the modern and recommended approach to addressing these warnings without completely disabling such checks?