Literal types
In addition to the general types string and
number, we can refer to specific strings and
numbers in type positions.
let changingString = "Hello World";
type: string
const constantString = "Hello World";
type: "Hello World"
function printText(
s: string,
alignment: "left" | "right" | "center"
) {}
function compare(
a: string,
b: string
): -1 | 0 | 1 {
return a === b ? 0 : a > b ? 1 : -1;
}