Created
July 12, 2017 09:14
-
-
Save hn3000/02d75ab05921701412cd4247f8e2e909 to your computer and use it in GitHub Desktop.
collection of typescript typing snippets
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
// 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