嗨,我正在编写一个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
再次感谢您的帮助。
如果将"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。