On Github SBats / typescript-talk
interface Image { url: string; title: string; likes?: number; } class Picture implements Image { url: string; title: string; constructor(mySweetTitle: string) {...} }
fetch(url, {method: 'GET'}) .then((response) => { let myPicture = response.json() as Picture; ... });
function getElementHash<T>(element: T): string { return element.title.getHash + element.url.getHash; } let myPicture = new Picture(name, url); let myvideo = new Video(name, url); let pictureHash = getElementHash(myPicture); // Type: Picture let videoHash = getElementHash(myVideo); // Type: Video
/** * Creates a Picture object * @constructor * @param {string} url Url of the image * @param {string} title Title of the image * @param {number} [likes=0] Number of likes given by the community */ function Picture(url, title, likes) { if (likes === undefined) { likes = 0; } this.url = url; this.title = title; this.likes = likes; }
declare namespace MyNamespace { export interface Picture { /** * Url of the picture. */ url: string; /** * Number of likes given by the community. * * Default value: '0' */ likes?: number; }
"compilerOptions": { "target": "es5", "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "outFile": "./build/tsc.js", "sourceMap": true }, "exclude": [ "node_modules", "build" ]
export class UserModel extends Models.Model implements IModels.IModel { ... }
myWonderfullMethod(param1: string, param2: any): Array<number> { ... }