Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 408
Brian Sullivan Avatar asked May 16 '18 20:05

Brian Sullivan


1 Answers

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.

like image 60
Brian Sullivan Avatar answered Nov 09 '22 14:11

Brian Sullivan