【问题标题】:Visual Studio 2012 TypeScript project ignoring two files during compileVisual Studio 2012 TypeScript 项目在编译期间忽略两个文件
【发布时间】:2012-10-13 23:54:12
【问题描述】:


我有一个 Visual Studio 2012 TypeScript 项目。当我第一次制作项目时,我添加了 2 个新的 .ts 文件,它们是 Framework.ts 和 Graphics.ts。我最近添加了两个 TypeScript 文件作为声明文件,并将它们命名为 .d.ts,例如 Framework.d.ts 和 Graphics.d.ts。有趣的是,所有 4 个文件都将 Build Action 属性设置为 TypeScriptCompile,但其中只有 2 个构建(Framework.ts 和 Graphics.ts),其他 .d.ts 文件仍然具有关于 a 的原始 .js 构建代码形状模块。我想也许 .d.ts 扩展名有问题,并将这些文件重命名为 Framework_d.ts 和 Graphics_d.ts。这也没有建造它们!

在这一点上,我不知所措。我查看了csproj文件:

<TypeScriptCompile Include="Framework\Framework.d.ts" />
<Content Include="Framework\Framework.d.js">
  <DependentUpon>Framework.d.ts</DependentUpon>
</Content>
<Content Include="Graphics\Graphics.d.js">
  <DependentUpon>Graphics.d.ts</DependentUpon>
</Content>
<Content Include="TestPages\SpriteBatch.html" />
<TypeScriptCompile Include="Framework\Framework.ts" />
<Content Include="Framework\Framework.js">
  <DependentUpon>Framework.ts</DependentUpon>
</Content>
<Content Include="Graphics\Graphics.js">
  <DependentUpon>Graphics.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="Graphics\Graphics.d.ts" />
<TypeScriptCompile Include="Graphics\Graphics.ts" />

然后是打字稿编译器的执行命令:

<Target Name="BeforeBuild">
  <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

这确实也应该构建这些文件。我只是不知道它为什么拒绝。有谁知道如何解决这个问题?

【问题讨论】:

    标签: typescript


    【解决方案1】:

    如果它们是你所说的声明文件,那么它们将没有 javascript 输出。我认为您不需要将这些“添加”到项目中,或者至少不需要对它们应用 TypeScriptCompile 构建操作。您可以使用

    将它们包含在其他源文件中
    ///<reference path="Framework\Framework.d.ts" 
    ///<reference path="Graphics.d.ts" 
    

    所以他们看到了声明。

    【讨论】:

    • 如果我使用 import Framework = module("Framework");然后我收到一个错误,因为 require() 函数不存在。因为 js 中生成的行是 var Framework = require("Framework");有什么我缺少的东西吗?
    • 所以你需要在你的网页上包含 require.js (在编译的打字稿之前)。如果您设置编译标志 --target AMD,TypeScript 会生成 AMD 兼容代码(有关如何编辑 VisualStudio 项目文件以添加必要的编译器标志,请参阅此线程;stackoverflow.com/questions/12811034/… 在底部的注释中;这包括源标志maps 也是如此)然而,即使 TypeScript 会生成对 require 的调用,它也不包含 require 功能。
    • 另外,您需要扩展模块的完整路径,因此它需要是:Framework = module("Framework\Framework.ts")。如果 Framework.ts 是真正的打字稿代码,则此方法适用于编译后的 javascript。如果您只是包含声明,请使用 ///reference 的东西..
    【解决方案2】:

    我不确定这是不是你的情况, 但是 .ts 文件编码存在一些问题。

    很遗憾,TypeScript 无法编译 UTF-8 with 签名。 您可以通过以下方式选择另一个保存选项 “文件”-->“高级保存选项”--> 选择“不带签名的UTF-8”。

    检查当前问题。 http://typescript.codeplex.com/workitem/85

    谢谢

    【讨论】:

      猜你喜欢
      • 2012-10-14
      • 2012-09-25
      • 2012-10-30
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      相关资源
      最近更新 更多