如果没有人找到一种“官方”的方式来做这件事,你可以把评论放在你知道的代码中
erased
来自发出的javascript。这绝对是一个黑客,但根据您的用例,它可以为您工作:
interface TSOnlyComment {
// this comment will definitely not appear in the JS
}
所以这是一个名为
TSOnlyComment
. 您可以重用该接口进行多个注释,因为typescript将其解释为
interface merging
以下内容:
interface TSOnlyComment {
// This only appears in TS, not JS
}
const javaScriptAwesomenessFactor = 1e9; // JS rules!
interface TSOnlyComment {
// Just kidding, TS is better than JS.
}
// let's print out how awesome JS is
console.log(javaScriptAwesomenessFactor);
interface TSOnlyComment {
// Ha ha, we are laughing at JS behind its back.
}
它应该发出JS之类的东西(取决于
--target
):
var javaScriptAwesomenessFactor = 1e9; // JS rules!
// let's print out how awesome JS is
console.log(javaScriptAwesomenessFactor);
所以,也许这对你有用?祝你好运!