简体   繁体   English

在不编译.js的情况下生成打字稿定义文件(d.ts)

[英]Generating Typescript Definition File (d.ts) without compiling .js

I'm generating d.ts files from ts files. 我正在从ts文件生成d.ts文件。 However, I see no way to prevent the generation of the .js files while doing this. 但是,在执行此操作时,我看不到任何方法来阻止.js文件的生成。

The command i am using is: 我正在使用的命令是:

tsc --declaration test.ts

This generated both a test.d.ts as a test.js. 这生成了一个test.d.ts作为test.js。 However I only want it to generate a test.d.ts file. 但是我只希望它生成一个test.d.ts文件。

Are there any options to do so? 有什么选择吗?

There is no flag you can pass to the compiler at the current time that will prevent it from creating the JavaScript file. 当前没有可传递给编译器的标志,它将阻止编译器创建JavaScript文件。 The main purpose of the compiler is to create the JavaScript and the additional features like d.ts files and source maps are in addition to that core feature. 编译器的主要目的是创建JavaScript,并且除了该核心功能以外,还包括d.ts文件和源映射之类的其他功能。

There is no harm asking for this as an enhancement over at http://typescript.codeplex.com/workitem/list/basic 将其作为对http://typescript.codeplex.com/workitem/list/basic的增强,这没有什么害处。

One option would be to use the --out otherFile.js parameter and just discard/ignore what was generated. 一种选择是使用--out otherFile.js参数,而只是丢弃/忽略生成的内容。

So your command could look like: 因此,您的命令可能类似于:

tsc --declaration test.ts --out ignoreMe.js

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM