打字稿:从嵌套模块导入
Typescript: Import from nested modules
我是 运行 一个 React 应用程序。由于以下错误消息,下面的代码不起作用:
import =
is not supported by @babel/plugin-transform-typescript
Please consider using import <moduleName> from '<moduleName>';
alongside Typescript's --allowSyntheticDefaultImports option.
apiTypes.d.ts
declare module ModuleA {
declare module ModuleB {
export interface ModuleABInterface {
}
}
}
token.ts
import ModuleABInterface = ModuleA.ModuleB.ModuleABInterface
let test: ModuleABInterface
从嵌套模块导入的正确解决方案是什么?
嵌套ES6模块是不可能的。 TypeScript namespaces (that were originally called "modules") can be nested, but should be avoided。是的,从 中导入 是不可能的——你只能导入命名空间对象本身,使用普通的 ES6 import
声明(不是弃用的 import =
语法),然后访问它们的属性。
我是 运行 一个 React 应用程序。由于以下错误消息,下面的代码不起作用:
import =
is not supported by @babel/plugin-transform-typescript Please consider usingimport <moduleName> from '<moduleName>';
alongside Typescript's --allowSyntheticDefaultImports option.
apiTypes.d.ts
declare module ModuleA {
declare module ModuleB {
export interface ModuleABInterface {
}
}
}
token.ts
import ModuleABInterface = ModuleA.ModuleB.ModuleABInterface
let test: ModuleABInterface
从嵌套模块导入的正确解决方案是什么?
嵌套ES6模块是不可能的。 TypeScript namespaces (that were originally called "modules") can be nested, but should be avoided。是的,从 中导入 是不可能的——你只能导入命名空间对象本身,使用普通的 ES6 import
声明(不是弃用的 import =
语法),然后访问它们的属性。