npm包,类似于打印版本和转换版本之间不兼容的类

问题描述 投票:0回答:1

嗨,我正在编写一个npm包,用打字稿编码并编译。

该包现在已用于打字稿应用程序,但我有1个错误:

[ts]
Argument of type 'import("/home/chriss/Sites/ORM/connection").DB' is not assignable to parameter of type 'import("/home/chriss/Sites/ORM/dist/connection").DB'.
Property 'connections' is protected but type 'DB' is not a class derived from 'DB'.

同一个类只有1是打字稿一个,另一个是已编译的

我这样声明:

import { DB } from "@unicoderns/orm/connection"
...
constructor(config: Config, baseURL: string) {
    this.config = config;
    this.db = new DB({ dev: config.dev, connection: config.dbconnection });
}

然后像这样调用模型:

this.usersTable = new users.Users(jsloth.db);

其中jsloth.db是第一个代码中的this.db。

这是在npm包中期待的:

constructor(DB: DB, privacy?: string);

我能做什么?

编辑1:

包已经发布,来源可在:

https://github.com/unicoderns/ORM

肮脏和快速的解决方法是将| any添加到第56行model.ts预期的constructor(DB: DB | any类型

这应该纠正:)

使用此包的库也是OpenSource,代码可以在以下位置找到:

https://github.com/unicoderns/JSloth

一旦你从包中删除| any,几个文件应该“大喊”IDE中的错误,但可能仍然有效,如第57和58行的source/system/apps/auth/endpoint/v1/index

再次感谢您的帮助。

typescript oop tsc transpiler
1个回答
1
投票

如果将"main"包的"typings"中的package.json@unicoderns/orm字段指向dist子目录,则@unicoderns/orm的导入将转到该子目录。当您导入@unicoderns/orm的非主模块时,例如在source/system/lib/core.ts第25行:

import { DB } from "@unicoderns/orm/connection"

你需要使用dist中的路径来保持一致性:

import { DB } from "@unicoderns/orm/dist/connection"

有关更多信息,请参阅this thread,特别是this comment

© www.soinside.com 2019 - 2024. All rights reserved.