Published On Nov 17, 2021
All FREE courses - https://automationstepbystep.com/
Arrays
Tuple
Enum
Unknown
Any
Void
Union of Types
#TypeScriptTutorials
Stories by Raghav - https://automationstepbystep.com/stor...
My Udemy Courses - https://automationstepbystep.com/udem...
Arrays
to work with array of values
let list1: number[] = [1,2,3]
let list2: Array<number> = [1,2,3]
Tuple
for fixed values but different types
let x: [string, number]; // declare
x = ["hello", 10]; // initialize
x = [10, "hello"]; // error
console.log(x[0].substring(1)); // accessing
Enum
giving more friendly names to sets of values
enum Color {Red=3, Green, Blue,}
let c: Color = Color.Green;
console.log (c)
By default, enums begin numbering their members starting at 0
You can change this by manually setting the value of one of its members
Unknown
when describing a variable without knowing the type of values it may have to store
let notSure: unknown = 4;
notSure()
notSure.toUpperCase()
(notSure as string).toUpperCase()
Any
when not knowing the type of the value,
can opt out of type checking using any
let anyValue: any = 10;
anyValue = true
anyValue = ‘hello’
anyValue()
anyValue.toUpperCase()
Void
absence of any type
commonly used as return type of functions that do not return any value
function warnUser(): void {
console.log("This is my warning message");
}
Union of Types
Multiple types for same variable
let peopleAllowed: number | boolean
peopleAllowed = 10
peopleAllowed = false
Can use when the type of value is unknown or not under your control
Coming from external source or user
Intellisense support
Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you
You can support my mission for education by sharing this knowledge and helping as many people as you can
If my work has helped you, consider helping any animal near you, in any way you can.
_______ ONLINE COURSES TO LEARN _______
https://automationstepbystep.com/free...
Never Stop Learning
Raghav