mapbox-gl-draw 的打字稿定义 d.ts

eth*_*han 7 typescript mapbox-gl-js typescript-typings typescript2.0

我试图为 mapbox-gl-draw 项目创建一个类型化定义。但是失败了。有人可以给一些提示吗?

javascript文件是这样的

'use strict';

var Setup = require('./src/setup');
var Options = require('./src/options');
var API = require('./src/api');
const Constants = require('./src/constants');

var Draw = function(options) {
  options = Options(options);

  var ctx = {
    options: options
  };

  var api = API(ctx);
  ctx.api = api;

  var setup = Setup(ctx);
  api.addTo = setup.addTo;
  api.remove = setup.remove;
  api.types = Constants.types;
  api.options = options;

  return api;
};

module.exports = Draw;

window.mapboxgl = window.mapboxgl || {};
window.mapboxgl.Draw = Draw;
Run Code Online (Sandbox Code Playgroud)

我的 index.d.ts 就像

declare namespace mapboxgl {
    export function Draw(options?:any):any

}
declare module 'mapbox-gl-draw' {
    export = mapboxgl;
}
Run Code Online (Sandbox Code Playgroud)

juF*_*uFo 1

对于这个 JavaScript:

var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v8',
  center: [40, -74.50],
  zoom: 9
});
Run Code Online (Sandbox Code Playgroud)

例如,您可以创建mapOptions:

interface MapOptions {
 container?: string;
 style?: string,
 center?: number[];
 zoom?: number;
}


declare module "mapbox-gl-draw" {

}
Run Code Online (Sandbox Code Playgroud)