Back to questions
JuniorTheoryCommon
What does tsc report for this program?
let title: string = "Report";
title = null;
console.log(title);An error: null cannot be assigned to the string type
- Expecting
nullto fit any type, as in JavaScript or with strict mode off: understrict,nullhas its own type, andstringdoes not accept it. - Blaming the
let: aletmay take a new value of its declared type; here onlynullbreaks thestringdeclaration.
- How do you declare a variable that may hold either a string or
null? - Which compiler option makes
nullandundefinedseparate types, and which flag turns it on?