在打字稿中重新导出lodash导出

时间:2016-10-27 09:19:37

标签: javascript node.js typescript

我在我的打字稿项目中使用lodash和lodash的打字。 除了我有一些私有的npm模块与我在不同的项目中使用的工具。 它导出类似的方法:

export * from './src/stringStuff';
export * from './src/httpStuff';

我想要做的是提供lodash与utils repo。所以它看起来像那样:

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的错误:

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但是也会收到错误消息,这很奇怪。为什么这样,我该如何解决?是错误的导入/导出还是输入文件错误?

1 个答案:

答案 0 :(得分:0)

我发现有关不同库结构的文本: 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,但我不知道是否有其他解决方案......

相关问题