Literal Types
Literal Narrowing
// TypeScript sets the type to be string
let hiWorld = "Hi World";
// TypeScript sets the type to be "Hello World", not string
const helloWorld = "Hello World";String Literal Types
type Easing = "ease-in" | "ease-out" | "ease-in-out";
animate(dx: number, dy: number, easing: Easing) {
...
}
animate(0, 0, "test"); // ErrorNumeric Literal Types
Boolean Literal Types
Last updated