I have a vue2 application and I am looking to incorporate TypeScript into some service files without modifying the existing js/vue files.
To enable TypeScript support, I utilized vue-cli which allowed me to successfully add a myService.ts file containing a TypeScript function called myFunction. Within this file, Vue properly detects type issues. I am able to import this service into a vue component file - myComponent.vue (which contains js code) and use it seamlessly.
The structure of myFunction is as follows:
function myFunction(x: number, y: number): number {
const a: number = 3;
const b: number = 2;
return a + b + x + y;
}
However, when invoking myFunction from myComponent.vue with incorrect parameters such as myFunction("str1", "str2")
, Vue does not flag any issues, even though string parameters should be invalid.
I can execute npm run serve without encountering any warning or error messages.
Is there a way to prompt Vue to detect these errors? Can TypeScript issues within js code be identified?