在 Visual Studio 2015 CTP6 + TypeScript 1.4 中使用外部模块 [英] Using external modules in Visual Studio 2015 CTP6 + TypeScript 1.4

查看:17
本文介绍了在 Visual Studio 2015 CTP6 + TypeScript 1.4 中使用外部模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何导入模块.当我在 .ts 文件的顶部写一条语句时,例如:

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");

我收到以下错误:

除非提供了--module"标志,否则无法编译外部模块.

Cannot compile external modules unless the '--module' flag is provided.

在以前版本的 Visual Studio 中,有一个包含项目属性的区域,允许您控制某些 TypeScript 配置.它在 Visual Studio 2015 中的什么位置?

In previous versions of Visual Studio, there was an area with the Project's properties that allowed you to control some TypeScript configuration. Where is this located in Visual Studio 2015?

有人知道如何启用导入外部模块吗?

Does anyone know how I can enable importing external modules?

推荐答案

以下是为每个项目配置 typescript 的步骤:

Here are the steps to configure typescript per project:

  1. 卸载您的项目.如果您的项目基于 MVC 6 模板,您会发现 MSBuild 配置非常少.

导航到:C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript*

* 这假设您在默认位置安装了 VS.

找到 Microsoft.TypeScript.Default.props 文件并打开它.无需提升权限,我们只会从中阅读.

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

它应该看起来像:

<?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>

  • 复制整个 PropertyGroup 元素,并将其粘贴到您的 .kproj 文件中;它需要在 Project 元素下.

  • Copy the entire PropertyGroup element, and paste it somewhere in your .kproj file; it needs to be under the Project element.

    TypeScriptModuleKind 从 none 修改为您的模块定义.选项是 AMDCommonJS.

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

    保存 .kproj 文件,然后重新加载您的项目.

    Save the .kproj file, and reload your project.

    您不应再收到有关包含模块的编译时错误.

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

    这篇关于在 Visual Studio 2015 CTP6 + TypeScript 1.4 中使用外部模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆