Skip to content

Instantly share code, notes, and snippets.

@bitsmuggler
Last active November 1, 2016 14:34
Show Gist options
  • Save bitsmuggler/05fa3a554bc328142016cfb26375c21e to your computer and use it in GitHub Desktop.
Save bitsmuggler/05fa3a554bc328142016cfb26375c21e to your computer and use it in GitHub Desktop.
Typescript Hints
//#1: Creating members via constructor
class Car {
constructor(public engine: string) {
}
}
//#2: Structure of a typescript class
//Class
//-- Fields
//-- Constructors
//-- Properties
//-- Functions
//All class members are public per default.
//#3: Property Limitation
// Properties doesn't work in every browser.
// Alternative targeting ES3 or don't use properties.
//#4: Casting Types
//This fails.
var table : HTMLTableElement = document.createElemente('table');
//This succeeds
var table: HTMLTableElement = <HTMLTableElement>document.createElement('table');
//#5: params function parameter
myFunction(...elements: string[]) {
}
//#6: optional members in an interface
interface IAutoOptions {
engine: IEngine;
basePrice: number;
state: string;
make?: string;
model?: string;
year?: number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment