asg*_*ant 2 typescript arcgis-js-api esri-maps
我觉得这里有一些非常简单的东西.我已经得到了我建立了一个使用ESRI的ArcGIS的API的一类,但是当我导入从类型定义arcgis-js-api的d.ts文件,我得到的打字稿错误"无法使用'新’与它的类型没有一个电话或一封表达构建签名."
例如:
import * as IMap from 'esri/Map';
export class Foo {
bar: (Map: IMap) {
const map = new Map(); // <-- error here
}
}
Run Code Online (Sandbox Code Playgroud)
d.ts文件中的相关摘录:
declare namespace __esri {
/* snip */
interface Map extends Accessor, LayersMixin {
allLayers: Collection;
basemap: Basemap;
ground: Ground;
}
interface MapConstructor {
new(properties?: MapProperties): Map;
}
export const Map: MapConstructor;
/* snip */
}
declare module "esri/Map" {
import Map = __esri.Map;
export = Map;
}
Run Code Online (Sandbox Code Playgroud)
看起来类型定义对我来说是正确的,那么我做错了什么会使得Typescript认为该IMap类型没有构造函数?
在Map您的参数是实例IMap类型.如果您想将其键入为构造函数,请将其键入typeof IMap:
bar (Map: typeof IMap) {
const map = new Map();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2263 次 |
| 最近记录: |