Tyler Jones Tyler Jones - 1 year ago 109
TypeScript Question

Where do I put typescript definitions and how do i write them when the object already has a definition

I'm sorry for this question, because I know the answer has to exist somewhere, but I don't think i have a deep enough understanding of Typescript to even know what I'm supposed to be searching for.

My problem is that I have added a jquery plugin called

as well as a global variable on the window object named
which is for communicating to my c# wrapper app.

These items are causing errors when I compile, and I want to get rid of the errors, so what am I supposed to do? I thought maybe I'm supposed to created definitions for these items, but I can't find any documentation for how to do that, since
already has a definition, because I installed the
definition from
, and it appears maybe the
object already has a definition as well.

Here are the errors I'm getting:

Property 'typeahead' does not exist on type 'JQuery'.
Property 'bound' does not exist on type 'Window'.

So, what do I do to make the errors stop? If i'm supposed to write definitions, where do the definitions go, and how do I write definitions for objects that already have definitions?

I tried making a file in the root of my project called
, but as soon as I created that file, with no code in it, i got this error:

WARNING in ./src/index.d.ts
Module build failed: Error: Debug Failure. False expression: Output generation failed

I tried adding interface statements, module declaration statements, and namespace declaration statements, and nothing can make the error go away. Is the filename wrong? Is the file supposed to be in a certain location?

I've read the documenation here: https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html
But I can't see anything about where the definition go, or how to write definitions for objects that already exist.

thanks in advance for any help anyone can give.


Definitely Typed, nor Typings contain definitions for the typeahead library I'm using, nor for the global
object i created. I need to understand how to manually get rid of these errors.

Answer Source

You can get the definitions for typeahead from DefinitelyTyped, and then you can add it to whichever files are using it this:

/// <reference path="./pathFromFile/typeahead.d.ts" />

If you want to create or extend definitions for a JS library, you'll have to create .d.ts file that can go anywhere as long as your reference path is correct. I use this guide which was pretty helpful for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download