javascript - 如何导出在打字稿中生成的导入命名空间?
问题描述
我的项目是一个微服务项目,它从文件中生成一些打字稿.proto
(不相关)。我想创建一个本地 npm 包来导出这些文件中的内容,以及一些利用这些文件中的 types/etc... 的帮助函数。
我试过了:
// package/index.ts
const ns = require('./generated/namespace');
cosnt helper = (a: string) => ns.someHelper(a);
module.exports = { ns, helper };
// package/generated/namespace
export namespace ns {
class SomeClass extends SomeType {
// etc......
}
interface ISomeType {
id?: (number|null)
// etc...
}
// and so on...
}
// another_container/index.ts
import { ns } from '@our/package';
当我这样做并将其放入另一个容器时,我收到此错误:
类型 'typeof import("/path/to/another_container/node_modules/package/dist/index")' 上不存在属性 'ns'。
这甚至可能吗?
解决方案
推荐阅读
- react-native - 从 React Navigation 尝试 Stack Navigator 时输入错误
- jquery - JQuery Sortable 正在扩大我的表格单元格的宽度
- python - 如何正确使用 asyncio run_coroutine_threadsafe 函数?
- android - 具有持久数据的离线网页缓存
- apache - 带有 URL 掩码的域重定向
- angular - 如何在 Angular for 循环中使用 Angular ngbootstrap 弹出框
- docker - 权限被拒绝时连接中止(权限被拒绝)
- postgresql - postgresql - 尝试在范围标准内对类似数据进行分组
- c - freopen() 关于缓冲 (setvbuf()) 的预期行为?
- ios - 如何解决我的拖放插座问题?