Understanding StrictNullChecks in TypeScript
Traditionally, null and undefined have been valid first class type citizens in JavaScript. TypeScript formerly did not enforce this, meaning you couldn't specify a variable to potentially be null or undefined.
Syntax Examples:
let y: number | null;
let z: number | undefined;
Exploring Union Types in TypeScript
While union types and intersection types are similar, they serve different purposes. There are situations where a parameter may need to be either a number or a string.
Syntax Example:
function padLeft(value: string | number | boolean) {
// code goes here
}
My Query:
I am curious if it's feasible to combine the concepts of `StrictNullChecks` and `Union Types`. For instance,
function padLeft(value: string | undefined | number | undefined) { // code snippet }
Can we apply `strictnullcheck` to function parameters? For example,
function padLeft(value: string | undefined) { // additional code here }