簡體   English   中英

用打字稿重新導出lodash導出

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM