我正在尝试对npm软件包的类型存根,该扩展使用index.d.ts
文件扩展了另一个npm-package,如下所示:
/// <reference types="pg" />
declare class PgCursor implements QueryConfig {
// Implementation omitted for brevity.
}
declare module 'pg-cursor' {
export = PgCursor
}
但是,这会产生错误:
src/@types/pg-cursor/index.d.ts:16:35 - error TS2304: Cannot find name 'QueryConfig'.
16 declare class PgCursor implements QueryConfig {
~~~~~~~~~~~
但是typings for the pg
package显然有这样的成员,据我了解,/// <reference
行应该使这些成员可用?
在文件中添加简单的import { QueryConfig } from 'pg'
只会产生更加神秘的错误:
src/@types/pg-cursor/index.d.ts:29:16 - error TS2665: Invalid module name in augmentation. Module 'pg-cursor' resolves to an untyped module at '/Users/mikl/Work/Pistor/torsk/node_modules/pg-cursor/index.js', which cannot be augmented.
29 declare module 'pg-cursor' {
~~~~~~~~~~~
那么我如何使TypeScript接受此类实现此接口?