musium
musium

Reputation: 3072

TypeScript - Visual Studio 2015 does not know about types in other files

I started using TypeScript in my ASP.Net MVC project. My filestructure looks like this:

Project
|-ts 
| |- Common
| | |-AppSettings.ts
| |-Components
| | |-DeleteModal.ts

AppSetttings.ts contains a class with some static properties representing global application constants:

namespace Ls.Common {
    export class AppSettings {
        public static readonly DeleteMethod = 'DELETE';
    }
}

DeleteModal.ts uses Ls.Common.AppSettings.DeleteMethod value as type for making an ajax request.

$.ajax({
    type: Ls.Common.AppSettings.DeleteMethod,
    url: this.config.deleteUrl,
    async: true
})
.done((data) => {
    // Display result
});

Visual Studio displays the following error in DeleteModal.ts:

Property 'AppSettings' does not exist on type 'typeof Common'.

Building the TS files using gulp works and creats the expected output. How can I make Visual Studio know about types in other TS files (inside of the same project)?

Upvotes: 0

Views: 44

Answers (2)

musium
musium

Reputation: 3072

Adding a refrence in DeleteModal.ts solved the problem:

/// <reference path="../common/appsettings.ts" />

Upvotes: 0

Phuc Tran
Phuc Tran

Reputation: 141

It seems that the Visual Studio didn't include the file in the analysis. Since gulp works, it's likely that gulp is using the correct tsconfig.json and the Visual Studio is not.

It's rather often that typescript configuration is included in the .csproj, and that configuration will override what is in tsconfig.json by default.

Please check if you having different configuration in different place mentioned above. The one in csproj looks like this

<PropertyGroup>
    <TypeScriptModuleKind>amd</TypeScriptModuleKind>
    <TypeScriptNoImplicitAny>True</TypeScriptNoImplicitAny>
    ....
</PropertyGroup>

Upvotes: 1

Related Questions