-
Notifications
You must be signed in to change notification settings - Fork 1
Typescript Cheatsheet
Jason Lewis edited this page Oct 1, 2021
·
4 revisions
Use the "as" operator. Example:
document.getElementById('name') as HTMLInputElement;
Add an ! after it. Example:
document.getElementById('name')!; // Must return an element or fail
Example:
let test: string[];
Example:
test: string | number | boolean
Example:
enum Role {
ADMIN,
READ_ONLY,
AUTHOR
}
Example:
test: 'value1' | 'value2'
Example:
enum Role {
ADMIN = 5,
READ_ONLY,
AUTHOR = 'Author'
}
Example:
let test: [number, string];
Example:
type MultiType = number | string;
function test(input1: MultiType) {...}