3


I have a Visual Studio 2012 TypeScript project. When I first made the project I added 2 new .ts files these were Framework.ts & Graphics.ts. I recently added two more TypeScript files to be declaration files and named them .d.ts such as Framework.d.ts and Graphics.d.ts. The interesting part is that all 4 of these files have the Build Action Property set to TypeScriptCompile yet only 2 of them build (Framework.ts and Graphics.ts) the other .d.ts files still have the original .js build code regarding a shapes module. I thought perhaps there was a problem with the .d.ts extension and renamed these files to Framework_d.ts and Graphics_d.ts. This didn't build them either!

At this point I am at a loss. I looked at the csproj file:

<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" />

And then the execute command for the typescript compiler:

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

This really should build these files too. I just have no idea why it refuses to. Does anyone know how to fix this?

Fenton
  • 241,084
  • 71
  • 387
  • 401

2 Answers2

2

If they are as you say, declaration files, then they will have no javascript output. I think you do not need to 'add' these to the project or at the very least, do not bother applying the TypeScriptCompile build action on them. You can just include them in the other source files using

///<reference path="Framework\Framework.d.ts" 
///<reference path="Graphics.d.ts" 

so they see the declarations.

Ezward
  • 17,327
  • 6
  • 24
  • 32
  • 1
    If I use the import Framework = module("Framework"); then I get an error as the require() function is not existing. as the generated line in the js is var Framework = require("Framework"); Is there something I'm missing for require? – IanelGreenleaf Oct 24 '12 at 17:06
  • So you need to include require.js on your webpage (before the compiled typescript). TypeScript generates AMD compatible code if you set up the compile flag --target AMD (see this thread on how to edit the VisualStudio project file to add the necessary compiler flag; http://stackoverflow.com/questions/12811034/targeting-es5-with-typescript-in-visual-studio in the comment at the bottom; this includes flags for source maps as well) However, even though TypeScript will generate the call to require, it does not include the require functionality. – Ezward Oct 24 '12 at 20:25
  • Also, you need the full path with extension to the module, so it would need to be: Framework = module("Framework\Framework.ts") . This works if Framework.ts is real typescript code the results in compiled javascript. If you are just include declarations, use the ///reference thing.. – Ezward Oct 24 '12 at 20:46
0

I'm not sure this is your case or not, but there are some issues regarding with .ts file encoding.

Unfortunately TypeScript cannot compile UTF-8 with signature. You might choose another save option by "FILE"-->"Advanced Save Options"--> Select "UTF-8 without signature".

Check current issue. http://typescript.codeplex.com/workitem/85

Thanks

popopome
  • 12,250
  • 15
  • 44
  • 36