简体   繁体   English

打字稿声明文件不遵循它自己的导入

[英]Typescript Declaration file not following it's own import

I have one main.ts script that I want to use as an entrypoint for my source code.我有一个main.ts脚本,我想将其用作源代码的入口点。 This main.ts script require multiple others typescript files and export then right away :这个 main.ts 脚本需要多个其他打字稿文件,然后立即导出:

export const Alpha = require('./Alpha.ts')
export const Beta = require('./Beta.ts')

I then used the typescript compiler to export the .d.ts declaration file of my source code.然后我使用 typescript 编译器导出我的源代码的 .d.ts 声明文件。 Now I have a main.d.ts file and two sub-scripts ( Alpha.d.ts and Beta.d.ts ).现在我有一个main.d.ts文件和两个子脚本( Alpha.d.tsBeta.d.ts )。

If I create a single .js script and import my main.d.ts entrypoint.如果我创建一个 .js 脚本并导入我的main.d.ts入口点。 I see my two other scripts correctly.我正确地看到了我的另外两个脚本。 But my autocompletion can't follow what is inside the alpha and beta declaration files.但是我的自动完成无法遵循 alpha 和 beta 声明文件中的内容。 I need to import them one by one to get what exported variables and function they have.我需要将它们一一导入以获取它们具有的导出变量和函数。

How can I access what is inside them by just importing my entrypoint ?如何仅通过导入我的入口点来访问其中的内容? I need to expose my source code declaration files without downloading the entire typescript source code.我需要在不下载整个打字稿源代码的情况下公开我的源代码声明文件。

Thank you for your help.感谢您的帮助。

I think it's:我想这是:

export * as Alpha from "./Aplha.ts";
export * as Beta from "./Beta.ts"

Look at: https://www.typescriptlang.org/docs/handbook/modules.html#re-exports看: https : //www.typescriptlang.org/docs/handbook/modules.html#re-exports

You mixed CommonJS / Node.js modules with TypeScript (ES6)您将 CommonJS / Node.js 模块与 TypeScript (ES6) 混合在一起

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

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