When creating a definition file in Typescript, how can I add an API key -
i'm new typescript, , create d.ts definition file javascript library, moviedb-js, can retreive film info themoviedb. i've looked existing definition @ definitely typed repository, , read fenton's guide on creating definition file, among others, however, i'm stuck translating next javascript bit:
var moviedb = require('moviedb')('your api key');
when creating module, have along lines of
declare module 'moviedb' { ... }
and in typescript code, import with:
import moviedb = require('moviedb')
clearly, without api key, doesn't work, , adding key in javascript illustration didn't work either. how can rewrite module definition in such way can define api key needed?
here concept moviedb.d.ts
declare module moviedb{ export interface imoviedb{ searchmovie(params:any,callback:function):imoviedb; // add together other methods here } } declare module 'moviedb' { function apiketacceptor(key:string):moviedb.imoviedb; export = apikeyacceptor; }
to utilize reference + import:
/// <reference path='../path/to/moviedb.d.ts'/> import moviedb = require('moviedb'); var moviedb = moviedb('your api key'); moviedb.searchmovie({query: 'alien' }, function(err, res){ console.log(res); });
for detailed illustration @ node.js definitions https://github.com/borisyankov/definitelytyped/blob/master/node/node.d.ts
typescript
No comments:
Post a Comment