Currently, I am coding in JavaScript with the help of a jsconfig.json
file to enhance TypeScript type checking.
Unfortunately, it appears that the TypeScript language server is not as advanced as needed to handle these specific situations. The error message I receive is as follows:
Types of property 'mode' are incompatible.
Type 'string' is not assignable to type '"production" | "development"'.
This error arises from the following code snippet:
return {
...
mode: isProd ? 'production' : 'development',
}
While I understand the reason behind this error and know how to resolve it in TypeScript (refer to ), JavaScript does not support type or const assertions.
Is there a proper workaround for this issue? I am using this configuration in multiple places, so I am hesitant to add //@ts-ignore
everywhere. Ideally, I would like to eliminate these 'string is not assignable to other strings' problems altogether, as they do not seem to be beneficial in JavaScript. The types are consistently inferred incorrectly in this case.