`tsc` 命令是否接受 .d.ts 文件?

Does the `tsc` command accept .d.ts files?

我有一个 .d.ts 文件,想将其编译成 .js 文件。这可以使用 tsc 命令吗?

我知道 tsc 命令可以获取任何 .ts 文件,然后将其编译为 .js 文件(我已经测试过)。但是,我无法将 .d.ts 文件作为输入,因为它没有为我输出任何 .js 文件。

我试过 tsconfig.json,目前我的文件是这样的:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "outDir": "ali_output_javascript"
    }
}

我还知道以下有关 .d.ts 和 .ts 文件的信息。 Typescript 声明文件 (.d.ts) 描述了 JavaScript 文件的形状。它允许您在 TypeScript 中使用现有的 JavaScript 代码,而无需在 TypeScript 中编写所有代码。打字稿文件(.ts)只是用打字稿书写时的标准文件扩展名。

从这篇媒体文章 (https://medium.com/jspoint/typescript-compilation-the-typescript-compiler-4cb15f7244bc) 中,它确实说 TypeScript 编译会查找文件扩展名 .ts 和 .d.ts:

Normally, you would use files or include option and provide file paths or glob patterns to include TypeScript files in the compilation process. However, you can drop the .ts extension from the glob pattern and let the TypeScript compiler search for the input files. When a glob pattern doesn’t have a file extension, TypeScript looks for the files ending with .ts or .d.ts extension in the directory pointed by the glob pattern. The .d.ts file is a TypeScript declaration file, we have discussed this file type in the Declaration Files lesson (coming soon). When the allowJS compiler-option is set to true, the TypeScript will also search for .js files as well.

如果您有任何建议,请告诉我,感谢您的宝贵时间。

您误解了 .d.ts 文件的含义。

它们不应该被转译为 .js 文件,.ts 文件应该被转译为 .js 文件 .d.ts 文件以实现强类型在 JavaScript IDE 中,或进一步用于 TypeScript 项目。

此外,.d.ts 不可执行且无法生成可执行文件,因为它们只是带有类型的空壳,在 TypeScript 中也称为 ambient declaration条款,这意味着“没有实施”。