如何声明导入其他类型的TypeScript模块

如何声明导入其他类型的TypeScript模块,typescript,Typescript,在Typescript 3.6.3中,我想为没有@types包的模块创建一个声明 其中一个函数参数在另一个已定义类型的模块中定义 geobuf.d.ts import Pbf = require('pbf'); declare module 'geobuf' { export function encode(obj: any, pbf: Pbf): Uint8Array; } 然而,当我这样做时,似乎TypeScript想要在模块扩充模式下运行(可以理解,因为我在声明文件中有一个导入)。

在Typescript 3.6.3中,我想为没有@types包的模块创建一个声明

其中一个函数参数在另一个已定义类型的模块中定义

geobuf.d.ts

import Pbf = require('pbf');

declare module 'geobuf' {
  export function encode(obj: any, pbf: Pbf): Uint8Array;
}
然而,当我这样做时,似乎TypeScript想要在模块扩充模式下运行(可以理解,因为我在声明文件中有一个导入)。我得到一个错误:

TS2665: Invalid module name in augmentation. Module 'geobuf' resolves to an untyped module at './node_modules/geobuf/index.js', which cannot be augmented.

如何创建同时引用现有类型化代码的声明文件?

编写声明时,声明模块“geobuf”应位于全局范围内。Typescript将其置于
global.d.ts
(全局命名空间)中。它是非模块中的顶级声明(其中模块是至少具有一个顶级导入或导出的文件)

这叫做

所以这
import Pbf=require('Pbf')需要在该模块声明中

希望能有帮助