typescript - Re-exporting all members of a TypeScript namespace
问题描述
I'm trying to re-export everything in a namespace from a new module. I've tried the following, which works to a degree:
// index.ts
import * as foo from 'foo';
function myFunction() {}
// Re-export everything in 'foo' along with myFunction
const thing = {
...foo,
myFunction,
}
export = thing;
This results in a type declaration as follows:
import * as foo from 'foo';
declare function myFunction();
declare const thing: {
Foo: typeof foo.Foo;
Bar: typeof foo.Bar;
myFunction: typeof myFunction;
};
export = thing;
But when I try to consume the types from the generated d.ts
file, I get an error:
'Foo' refers to a value, but used as a type
I suppose this is because Foo
and Bar
as declared as members of an object. Is there a way to achieve this re-export of existing types in a new module?
解决方案
你试过这个吗?
export * from 'foo';
export function myFunction() {}
推荐阅读
- flutter - 如何使用 https 在本地运行 Flutter Web 应用程序?
- matlab - 这个for循环可以矢量化以提高速度吗
- r - 使用 lapply 通过自定义函数传递数据帧变量时出错
- c++ - 一个程序来判断一个单词是否是回文
- javascript - 回调函数不适用于 js
- java - JSON到java的转换
- javafx - 为什么这个 JavaFX 双向绑定不起作用
- html - 为什么 CSS 径向渐变在 Edge 中不起作用?
- android - 在模拟类中捕获具有通用结果的挂起 lambda 参数
- javascript - 如何使 Material-UI 对话框可调整大小