Using external modules in Visual Studio 2015 CTP6 + TypeScript 1.4

后端 未结 1 1287
暖寄归人
暖寄归人 2021-02-09 10:37

I\'m trying to figure out how to import modules. When I write a statement at the top of my .ts file such as:

import a = require(\"a\");

I get t

相关标签:
1条回答
  • 2021-02-09 11:12

    Here are the steps to configure typescript per project:

    1. Unload your project. If your project is based on the MVC 6 template, you will find that the MSBuild configuration is pretty minimal.

    2. Navigate to: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript*

      * This assumes you installed VS in the default location.

    3. Locate the Microsoft.TypeScript.Default.props file and open it up. No need for elevated privileges, we will only be reading from it.

      It should look something like:

      <?xml version="1.0" encoding="utf-8" ?>
      <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
          <TypeScriptTarget>ES5</TypeScriptTarget>
          <TypeScriptCompileOnSaveEnabled>true</TypeScriptCompileOnSaveEnabled>
          <TypeScriptNoImplicitAny>false</TypeScriptNoImplicitAny>
          <TypeScriptModuleKind>none</TypeScriptModuleKind>
          <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
          <TypeScriptOutFile></TypeScriptOutFile>
          <TypeScriptOutDir></TypeScriptOutDir>
          <TypeScriptGeneratesDeclarations>false</TypeScriptGeneratesDeclarations>
          <TypeScriptSourceMap>true</TypeScriptSourceMap>
          <TypeScriptMapRoot></TypeScriptMapRoot>
          <TypeScriptSourceRoot></TypeScriptSourceRoot>
          <TypeScriptNoEmitOnError>true</TypeScriptNoEmitOnError>
        </PropertyGroup>
      </Project>
      
    4. Copy the entire PropertyGroup element, and paste it somewhere in your .kproj file; it needs to be under the Project element.

    5. Modify the TypeScriptModuleKind from none to your module definition. The options are AMD or CommonJS.

    6. Save the .kproj file, and reload your project.

    You should no longer get the compile-time error about including modules.

    0 讨论(0)
提交回复
热议问题