0

While compiling typescript I get an error:

src\app\foo.ts (129,25): Index signature of object type implicitly has an 'any' type. (7017)

on the following line:

const tmode = google.maps['DirectionsTravelMode'].DRIVING;

google.maps.DirectionsTravelMode doesn't exist in my typings file which I installed using typings install google.maps --save --ambient

I could add it but it would be lost when I checkout my project and reinstall the typings.

This is just one item in the file which is preventing my build from succeeding. What is the easiest way to get typescript to ignore this line? I have tested the code already and it runs correctly.

2
  • You could cast it to the type: tmode = (<any>google).maps.DirectionsTravelMode.DRIVING; Commented Mar 31, 2016 at 21:34
  • @CoreyAlix: That works! I had tried const tmode: any = ... but it didn't work. Please post an answer so I can accept! Thanks Commented Mar 31, 2016 at 21:42

2 Answers 2

2

You could extend the module yourself:

declare module google.maps {
    export enum DirectionsTravelMode {
        DRIVING
    }
}

NOTE: this would have to go in a declaration file such as mygoogle.d.ts.

Sign up to request clarification or add additional context in comments.

Comments

1

Index signature of object type implicitly has an 'any' type.

Instead of indexing just assert the any yourself:

const tmode = (google.maps as any).DirectionsTravelMode.DRIVING;

1 Comment

Thanks. This solution works and is helpful but @CoreyAlix already suggested similar in a comment above so I will give him a chance to answer before accepting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.