Consider the following code snippet:
function func1(param1: number, param2?: number) {
console.log(param1 + param2); // This line will throw an error 'param2' is possibly 'undefined'.(18048)
}
func1(5);
Now, let's take a look at this code snippet:
function func2(param1: string, param2?: string) {
console.log(param1 + param2); // This line of code is actually valid
}
func2('Hello');
Have you ever wondered why TypeScript doesn't flag an error in the second scenario when running in strict mode?