Sunday, May 27, 2018

Visual Studio Typescript Intellisense doesn't respect tsconfig.json baseUrl

Leave a Comment

I've got a web project in Visual Studio 2017 with a large TypeScript codebase. When I do a TypeScript build, I get no errors, and the resulting JavaScript is correct. However, my intellisense shows errors for any imports using a path based on the baseUrl configured in my tsconfig.json.

For example: enter image description here

When I change these to a relative path, the errors go away: enter image description here

Other editors' code inspection doesn't seem to have a problem with the former. We've confirmed it working in VS Code and JetBrains Rider.

My tsconfig.json is as follows:

{  	"compilerOptions": {  		"noImplicitAny": false,  		"noEmitOnError": true,  		"strictNullChecks": true,  		"removeComments": false,  		"sourceMap": true,  		"target": "es5",  		"module": "amd",  		"moduleResolution": "node",  		"baseUrl": "./Content/ts"  	},  	"exclude": [  		"node_modules"  	],  	"compileOnSave": true  }

I've tried as many different Visual Studio settings as I can find, but nothing seems to affect whether intellisense is able to find the modules. Again, the compiler itself has no issue finding them and building.

Update: Forgot to include that we also had the <TypeScriptBaseUrl> property defined in the .csproj file, set to the same value that's present in our tsconfig.json. This causes the TS build within Visual Studio to succeed, but doesn't seem to affect Intellisense.

1 Answers

Answers 1

Turns out the tsconfig.json file needs to be included in the project to get Intellisense to be happy. Not sure why the <TypeScriptBaseUrl> setting wasn't good enough. That's probably still a bug that needs to be reported.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment