Alon Alon -4 years ago 125
TypeScript Question

Adding declarations file manually (TypeScript)

I didn't find a declaration file for 'google-spreadsheet' so I'm trying to create one by myself:

in typings -> modules, I've added a new folder named "google-spreadsheet", and there I've added a new file named "index.d.ts" which has the following content:

export class GoogleSpreadsheet {

}


In the client file I have this:

import * as GoogleSpreadsheet from 'google-spreadsheet';


But 'google-spreadsheet' is marked with red, saying:


TS2307 Cannot find module 'google-spreadsheet'.


BTW I've NPM-installed 'google-spreadsheet' and it works JavaScriptly. Only the TypeScript bothers me here.

Any ideas how to solve that?

Answer Source

If you dont need to care about the typings inside this module you can only create a *.d.ts file and put the following content (e.g. create a typings.d.ts):

declare module 'google-spreadsheet';

To define the types inside the module you can change the above code to:

declare module 'google-spreadsheet' {
    // define the types...
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download