Typescript 在多repo项目类型脚本中从另一个存储库导入类型化对象
我正在尝试从多回购项目中的另一个存储库导入对象,typescript认为其中的类型不相同,但我确信它是相同的: 类型错误:Typescript 在多repo项目类型脚本中从另一个存储库导入类型化对象,typescript,Typescript,我正在尝试从多回购项目中的另一个存储库导入对象,typescript认为其中的类型不相同,但我确信它是相同的: 类型错误: TS2345: Argument of type 'import("/Users/user/javascript/packages/@shared/node_modules/knex/types/index")<any, unknown[]>' is not assignable to parameter of type 'Knex<a
TS2345: Argument of type 'import("/Users/user/javascript/packages/@shared/node_modules/knex/types/index")<any, unknown[]>' is not assignable to parameter of type 'Knex<any, unknown[]>'.
TS2345:类型为“import”(/Users/user/javascript/packages/@shared/node_modules/knex/types/index)的参数不能分配给类型为“knex”的参数。
如您所见,编译器正在使用节点_模块的完整路径引用导入对象的类型,并同时将其与当前文件夹的节点_模块进行比较,以发现它们不相同
知道如何解决这个问题吗?knex/types/index的默认导出是名称空间knex
export declare namespace knex {
class QueryBuilder {
static extend(
methodName: string,
fn: <TRecord extends {} = any, TResult = unknown[]>(
this: Knex.QueryBuilder<TRecord, TResult>,
...args: any[]
) => Knex.QueryBuilder<TRecord, TResult>
): void;
}
//... at the end of the file
export default knex;
因此,错误消息中的这两个导入实际上并没有引用相同的类型。这将是正确的导入:
import("/Users/user/javascript/packages/@shared/node_modules/knex/types/index").Knex<any, unknown[]>
import(“/Users/user/javascript/packages/@shared/node\u modules/knex/types/index”).knex
knex/types/index的默认导出是名称空间knex
export declare namespace knex {
class QueryBuilder {
static extend(
methodName: string,
fn: <TRecord extends {} = any, TResult = unknown[]>(
this: Knex.QueryBuilder<TRecord, TResult>,
...args: any[]
) => Knex.QueryBuilder<TRecord, TResult>
): void;
}
//... at the end of the file
export default knex;
因此,错误消息中的这两个导入实际上并没有引用相同的类型。这将是正确的导入:
import("/Users/user/javascript/packages/@shared/node_modules/knex/types/index").Knex<any, unknown[]>
import(“/Users/user/javascript/packages/@shared/node\u modules/knex/types/index”).knex