Reputation: 869
I am trying to write an interface to describe the foundation JQuery plugin. The plugin uses the first parameter to determine the child plugin that is called with the foundation plugin.
Below is an example of what i am trying to achieve.
/// <reference path="jquery.d.ts"/>
interface JQuery {
foundation(plugin:'reveal',action:string):void;
foundation(plugin:'dropdown',action:string,$el:JQuery):void;
}
How do i describe a fixed string parameter within a typescript definition?
Upvotes: 1
Views: 167
Reputation: 275799
You need to provide a non-specialized function signature. However this does open up possibilities of error:
interface JQuery {
foundation(plugin:'reveal',action:string):void;
foundation(plugin:'dropdown',action:string,$el:JQuery):void;
foundation(plugin:string,action:string,$el?:JQuery):void;
}
// SADLY
var foo:JQuery;
foo.foundation('sad','panda');
The reason is that there is no deterministic way for a compiler to always know ahead of time if a particular string is going to have an exact value. This string
might be coming from userinput/database. The idea here is to bring this information directly to your notice.
Upvotes: 2