[英]Can JavaScript/TypeScript re-export all named exports under an alias without importing first?
[英]re-export lodash exports in typescript
我在打字稿項目中使用lodash,並為lodash鍵入內容。 此外,我還有一些在不同項目中使用的utils私有npm模塊。 它導出如下方法:
export * from './src/stringStuff';
export * from './src/httpStuff';
我想要做的就是為lodash提供該utils回購。 所以看起來像這樣:
import {
forEach
} from '@foo/utils'
其中forEach
是lodash方法。 我的方法是在索引utils文件中添加lodash導出:
export * from 'utils';
export * from './src/stringStuff';
export * from './src/httpStuff';
現在,像上面的示例一樣,我可以導入和使用例如forEach
。 但是問題是類型腳本編譯器給我一個錯誤,即/files/@foo/utils/index.ts
沒有forEach
/files/@foo/utils/index.ts
成員:
ERROR in [default] /files/@foo/utils/index.ts:1:14
Module '"lodash"' uses 'export =' and cannot be used with 'export *'.
ERROR in [default] /files/@foo/utils/index.ts:24:4
Module '"/files/@foo/utils/index.ts"' has no exported member 'forEach'.
對我來說,我可以使用forEach
但也收到該錯誤消息,這很奇怪。 為什么會這樣,我該如何解決? 是錯誤的導入/導出還是輸入文件錯誤?
我發現有關不同庫結構的文本: https : //www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html
在我看來,最好將lodash定義為該示例文件中的模塊,因為我想它更像是UMD模塊? https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html
或在這里: https : //github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#support-for-umd-module-definitions
解決了我用自己的類型文件重新定義lodash的問題,但我不知道是否還有其他解決方案...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.