Created
July 17, 2016 21:43
-
-
Save amadeus/e0c157bddc70309b1aa8a5c6d8047649 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bar(x: string, y: number): string { | |
return x.length * y; | |
} | |
type PermissionOverwrite = { | |
id: string; | |
type: 'role' | 'member', | |
allow: number; | |
deny: number; | |
} | |
function total(numbers: Array<number>) { | |
var result = 0; | |
for (var i = 0; i < numbers.length; i++) { | |
result += numbers[i]; | |
} | |
return result; | |
} | |
function foo(a: string, b: number): { key: number, bool: boolean } {} | |
function foo(a: string, b: number): [ string, number ] { | |
} | |
function foo(a: string, b: number):object {} | |
function foo(a: string, b: number):object { | |
} | |
function foo(x: string): string { return x; } | |
function foo(a: string, b: number):void { | |
let durp: sayWhat = 2; | |
} | |
var x: boolean = someBool; | |
class Bar { | |
y: string; | |
someMethod(a: number): string { | |
} | |
} | |
let array: number[] = [1, 2, 3.14, 42]; | |
let theAnswer: number = array[3]; // 42 | |
let offTheEnd: number = array[100]; // No error | |
let array2: Array<string> = ["an alternate", "syntax", "for arrays"]; | |
let tuple: [string, number, boolean] = ["foo", 0, true]; | |
// Indexing into the array will return the type at a given index. | |
(tuple[0]: string); | |
(tuple[1]: string); | |
// Indexing into an statically unknown index will return a general type. | |
declare var unknownNumber: number; | |
// `void` is none of `string`, `number`, or `boolean` | |
(tuple[unknownNumber]: void); | |
(tuple[unknownNumber]: string|number|boolean); // OK | |
// Values written must be compatible with the type at that index. | |
tuple[1] = -1; | |
tuple[0] = false; | |
let object: {foo: string, bar: number} = {foo: "foo", bar: 0}; | |
(object.foo: string); | |
if (true) { | |
let durp: number = 2; | |
} | |
let case = 1; | |
switch (case) { | |
case 1: | |
let durp: sayWhat; | |
break; | |
case 2: | |
break; | |
} | |
function exampleMethod(someString: string, someRecord: Record): {resultString: string, resultString2: string} { | |
} | |
type State = { | |
errorMessages: Array<string>; | |
forceValidation: bool; | |
invalidFields: Array<string>; | |
submitting: bool; | |
}; | |
//----------------------------------------------------------------------------- | |
// Blah blah | |
//----------------------------------------------------------------------------- | |
function lol() { | |
// ... | |
} | |
type Props = { | |
name: string; // note: not null! | |
address: string; | |
}; | |
class AddressBookEntry extends React.Component<void /* DefaultProps */, Props, void /* state -- none in this component */> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment