2

我正在嘗試爲mapbox-gl-draw項目創建一個類型化的定義。但失敗了。有人可以提供一些提示嗎?mapbox-gl-draw的Typescript定義d.ts

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; 

我index.d.ts就像

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

} 
declare module 'mapbox-gl-draw' { 
    export = mapboxgl; 
} 

回答

0

對於此javascript:

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

例如,您可以創建的MapOptions:

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


declare module "mapbox-gl-draw" { 

} 
相關問題