Skip to content

Instantly share code, notes, and snippets.

@hn3000
Created July 12, 2017 09:14
Show Gist options
  • Save hn3000/02d75ab05921701412cd4247f8e2e909 to your computer and use it in GitHub Desktop.
Save hn3000/02d75ab05921701412cd4247f8e2e909 to your computer and use it in GitHub Desktop.
collection of typescript typing snippets
// make sure literal conforms to type
let var: Type = {
prop,
prop2: 123,
extra: 'value' // will give an error for extra properties
};
// make sure properties from type are spelled correctly
let var = <Type> {
porp, // will give an error if prop is required in Type, ignored if not
prop2: 123,
extra: 'value'
};
let var = x as Type; // nice cast without angle brackets, avoids type annotation on var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment