What is Narrowing in TypeScript?

To understand narrowing, let’s begin with a problem scenario. Suppose you’re working with a custom type called myType, which is defined as a union of string and null. type mytype = string | null; let a: mytype = “FOO”; console.log(a!.toLowerCase()); // foo The code above should print “foo” in lowercase.   Now, if you setContinueContinue reading “What is Narrowing in TypeScript?”