November 2018
Beginner
502 pages
10h 22m
English
The typeof keyword is a JavaScript keyword that returns a string that represents the type. So, we can use this in a condition to narrow down the type.
Let's go through an example:
type StringOrStringArray = string | string[];
function first(stringOrArray: StringOrStringArray): string { }
function first(stringOrArray: StringOrStringArray): string { if (typeof stringOrArray === "string") { return ...Read now
Unlock full access