After reviewing some examples provided by developers of TypeScript on GitHub, it seems they utilize stubs for interoperability with JavaScript:
declare module Backbone {
export class Model {
constructor (attr? , opts? );
get(name: string): any;
set(name: string, val: any): void;
set(obj: any): void;
save(attr? , opts? ): void;
destroy(): void;
bind(ev: string, f: Function, ctx?: any): void;
toJSON(): any;
}
...
}
interface JQuery {
fadeIn(): JQuery;
fadeOut(): JQuery;
focus(): JQuery;
html(): string;
html(val: string): JQuery;
show(): JQuery;
addClass(className: string): JQuery;
removeClass(className: string): JQuery;
append(el: HTMLElement): JQuery;
val(): string;
val(value: string): JQuery;
attr(attrName: string): string;
}
It may seem unusual, but can I avoid creating such stubs and simply use the jQuery object directly to call its methods? Considering TypeScript is a superset of JavaScript, one would assume that if something is achievable in JavaScript, it should be doable in TypeScript as well. What are the most effective ways to invoke JavaScript code from TypeScript?