Finding documentation on how to generate a .d.ts file from the Javascript library

I recently came across TypeScript, but am struggling a bit with the documentation. This seems to be quite a bit of a cold approach to things. Case and point.

Defining definitions for the JS library.

First of all, if you get the js file from NuGet, some of these nuget packages should be a d.ts file.
Secondly, I could not find any specific documentation on how to create the definition file.

I want to include the MarkerWithLabel library, which is an extension of the goi.maps api library.

Does anyone have a .d.ts file that they want to provide, or where I can get documentation on how to create / generate a file from the JS library.

edit: The library I'm looking for for this file is d.ts, MarkerWithLabel .

Here is the .d.ts file that I started creating based on the doc specification, but this does not seem to work at all.

/// <reference path="google.maps.d.ts"/> declare class MarkerWithLabelOptions { crossImage: string; handCursor: string; labelAnchor: google.maps.Point; labelClass: string; labelContent: any; labelInBackground: boolean; labelStyle: any; labelVisible: boolean; optimized: boolean; raiseOnDrag: boolean; } declare class MarkerWithLabel extends google.maps.Marker{ constructor(opt?: MarkerWithLabelOptions); } 

The implementation is as follows:

  var _mwlo =new MarkerWithLabelOptions({ position: this.CenterPoint.toLatLng() , draggable: true , map: this._map , labelAnchor: new google.maps.Point(22, 0) , labelStyle: {opacity: 1.0} }); var _mwl = new MarkerWithLabel(_mwlo); 

I get an error message stating that it cannot find a method that matches the given parameters.

+4
source share
2 answers

I ended up resolving this and included a working d.ts for others. It may be perfect, but it seems to work. ¯ \ _ (ツ) _ / ¯

  /// <reference path="google.maps.d.ts"/> declare class MarkerWithLabelOptions extends MarkerWithLabel { constructor(); crossImage: string; handCursor: string; labelAnchor: any; labelClass: string; labelContent: any; labelInBackground: boolean; labelStyle: any; labelVisible: boolean; optimized: boolean; raiseOnDrag: boolean; position: any; } declare class MarkerWithLabel extends google.maps.Marker { constructor(opts?:any); crossImage: string; handCursor: string; labelAnchor: any; labelClass: string; labelContent: any; labelInBackground: boolean; labelStyle: any; labelVisible: boolean; optimized: boolean; raiseOnDrag: boolean; } 

You may need to update the reference path for your solution.

+4
source

I wrote an article about writing TypeScript definitions , which I hope will help you get started.

The first step is to check if someone really created the definition on Definitely printed .

You cannot automatically generate a definition from JavaScript - although some types can be inferred - because the definitions are an additive process (i.e. adding information that does not exist in JavaScript), but there are quick ways to get started in the article.

+2
source

Source: https://habr.com/ru/post/1496042/


All Articles