Use Typescript to QA your Javascript in Visual Studio

images.pngIf you haven’t yet made the plunge into Typescript, and you should, here’s a way to leverage the Typescript engine to QA your Javascript code.

Open your Visual Studio 2019 Asp.Net project and go to your folder where your Javascript files are located.

2019-10-18 14_01_34-Window.png

Add a new file called tsconfig.json and enter this as the contents:

  "compileOnSave": true,
  "compilerOptions": {
    "strictNullChecks": true,
    "strict": true,
    "noEmitOnError": true,
    "noImplicitAny": true,
    "esModuleInterop": true

Rename one of the file by changing the .js extension to .ts

2019-10-18 14_05_08-Window.png

Note: Visual Studio may suggest you add a NuGet Typescript package, that’s fine todo, it’s harmless.

In my bad.ts file I have some Javascript that has a bug. The variable is defined after it is used. Javascript is fine with that, but when you rename the file to .ts, then the TypeScript engine will kick in and show you a red squiggly:

2019-10-18 14_07_02-Window.png

Hovering over it will show the error:

2019-10-18 14_08_03-Window.png

Fix the problem, verify no more squiggles and then rename the file to .js

I hope you move to Typescript, but if you can’t, then you can at least use the Typescript engine to verify your Javascript.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s