【问题标题】:typescript export imporatble from tsd从 tsd 导出打字稿
【发布时间】:2017-08-07 13:44:38
【问题描述】:

文件index.ts(使用 swagger-codegen 生成)

export * from './api/api';
export * from './model/models';

文件tsd.d.ts

...
/// <reference path="path/to/index.ts" />

typescript 2.2.1.

为什么我仍然需要在我的ts 文件中使用导入语句 (import myDTO from 'path/to/file/myDTO')? 我错过了一个概念,应该声明一个模块吗?

【问题讨论】:

    标签: typescript tsd swagger-codegen


    【解决方案1】:

    如果在 index.ts 中有导出语句 - 这使它成为 external module。为了使用外部模块 - 您必须导入它。

    更多info this matter

    【讨论】:

    • 一个子问题,如果你不介意的话。我可以在没有生成具有“已定义”、“要求”或其他模块机制的 JS 代码的情况下使用导入语句吗?我问这个,因为用 TS 编写 angular1 工厂,并且无法通过模块管理绕过生成的代码。
    • 恐怕不行。即使您将使用outFile + AMD/system 模块(请参阅typescriptlang.org/docs/handbook/compiler-options.html 中的 --module),转译器仍将使用相应的函数包装生成的单个文件。
    猜你喜欢
    • 2017-09-23
    • 2016-01-23
    • 2017-02-06
    • 1970-01-01
    • 2019-04-10
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    相关资源
    最近更新 更多