Why does TypeScript display errors only when assigning a string to a number, but not when assigning null to a number?
export type ArrayWithNumberOrString = Array<number | string>;
export type ArrayWithNumberOrNull = Array<number | null>;
function doSomethingWithNumbersOnly(array: number[]): number[] {
return array;
};
const numbersAndString: ArrayWithNumberOrString = [1, 2, 3, 'string'];
const numbersAndNull: ArrayWithNumberOrNull = [1, 2, 3, null];
doSomethingWithNumbersOnly(numbersAndString);
doSomethingWithNumbersOnly(numbersAndNull);