Sireini
Sireini

Reputation: 4262

Angular2- Is it possible to include an library without a typing file?

I am working on a google-maps app with angular 2 now I made this earlier in vanilla javascript. But there I use libraries as RichMarkers and infoBox, now my question is, is it possible to include these without using a typing file (because there aren't yet) I tried the infoBubble from definetlyTyped, but it is not matching with the angular2-google-maps so it throws me errors.

Does anybody know how to include a library without a typing file is this possible?

This is my component code:

import {Component, Directive} from '@angular/core';
import {GoogleMapsAPIWrapper} from 'angular2-google-maps/core';

declare var fontawesome:any;
declare var RichMarker:any;
declare var RichMarkerPosition:any;
declare var google:any;


@Component({
    selector: 'poly-layer',
    template: '<div></div>'
})
export class PolyLayer {
    constructor(private _wrapper: GoogleMapsAPIWrapper) {
        this._wrapper.getMap().then((map) => {          

            var myLatLng = new google.maps.LatLng(-25.363882, 131.044922);
            var marker_html = '<div id="test"><div class="rich-marker"><span class="number-id">'+ 'number' + '</span></div></div>';

            var marker = new RichMarker({
                position: myLatLng,
                map: map,
                flat: true,
                anchor: RichMarkerPosition.MIDDLE,
                content: marker_html
            });



            marker.setMap(map);
        });
    }
}

Where google is not defined in the index of richmarker: RichMarker.prototype = new google.maps.OverlayView();

How do I define this ?

Here a PLUNKER

This is the error

Upvotes: 0

Views: 559

Answers (2)

turoni
turoni

Reputation: 1435

If you are using this with typescript just use any.

constructor(restService: RestService, $state: any, FileSaver: any) {
    this.restService = restService;
    this.$state = $state;
    this.FileSaver = FileSaver;

For restService I used a type but for $state I wasn't sure what it was and I just used any.
angular-file-saver also didn't have a typing so I also used any.

Upvotes: 0

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657338

You can use declare foo; to tell the TS compiler that it safely can assume foo exists and it won't produce an error if your code refers to foo.

Upvotes: 2

Related Questions