Skip to content

Instantly share code, notes, and snippets.

@newmanbrad
Created August 10, 2016 16:43
Show Gist options
  • Save newmanbrad/d3c8bc86d9fd1749c65f251f76a72b7d to your computer and use it in GitHub Desktop.
Save newmanbrad/d3c8bc86d9fd1749c65f251f76a72b7d to your computer and use it in GitHub Desktop.
Typescript: Type Annotation Example
/**
* Example: Type Annotation
*
* Type annotations remove the need for the compiler to infer the type.
*
* Available Types:
* Boolean: simple true/false value
* Number: floating point values
* String: textual data
* Array: ordered collection of data
* Tuple: array with fixed number of elements
* Enum: named numeric sets
* Any: unsure of value type
* Void: no value, the opposite of Any
*
*
* Docs: https://www.typescriptlang.org/docs/handbook/basic-types.html
*/
let thisIsAString: string = "This is my string.";
thisIsAString = 42; // Error: cannot assign 'string' to a 'number'
function createNumber(): number {
return 55;
}
thisIsAString = createNumber(); // Error cannot assign 'string' to a 'number'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment