gpt4 book ai didi

npm - 如何创建一个 "external module" typescript 定义文件以包含在 npm 包中?

转载 作者:搜寻专家 更新时间:2023-10-30 20:40:33 25 4
gpt4 key购买 nike

我最近添加了 a typescript definition file对于开源 redux-ui-router 库,但我现在在 Typescript 1.7.3 中遇到如下错误:

error TS2656: Exported external package typings file 'C:/.../node_modules/redux-ui-router/index.d.ts' is not a module. Please contact the package author to update the package definition.

我正在尝试在我的 typescript 文件中使用这样的代码导入这个库:

import ngReduxUiRouter from "redux-ui-router";

我是 Typescript 的新手,我找不到关于这个定义文件在包含在 npm 包中时应该是什么样子的清晰描述。 There's a wiki entry它讨论了 npm 包的类型,但除了重复应该使用外部模块的方向之外,没有一个具体的例子可以引用。

更正我尝试删除 declare module "redux-ui-router"{ 代码,这似乎在重新启动 webpack 后有效,我正在使用它来编译所有内容(为了简洁起见,我删除了评论):

export interface ReduxUIRouterAction {
type: string;
payload: any;
}
export interface ReduxUIRouterState {
currentState: Object;
currentParams: Object;
prevState: Object;
prevParams: Object;
}
export function router(state: ReduxUIRouterState, action: ReduxUIRouterAction): ReduxUIRouterState;
export var ngReduxUiRouter: string;
export function stateGo(to: string, params?: Object, options?: Object): ReduxUIRouterAction;
export function stateReload(state: any): ReduxUIRouterAction;
export function stateTransitionTo(to: string, params?: Object, options?: Object): ReduxUIRouterAction;
export default ngReduxUiRouter;

当将其包含在 npm 包中时,这组更改是否符合预期?

最佳答案

Is this set of changes what would be expected when including this in an npm package?

是的。导出需要是文件的根级别。

换句话说:环境文件不是外部模块

关于npm - 如何创建一个 "external module" typescript 定义文件以包含在 npm 包中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34030542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com