I am migrating some JS code to TS and I'm faced with an issue of differentiating between a null type in TypeScript versus just giving a null value of a field in an object.
Here is a dummy example:
export const performProcedure = () => {
let newPerson = {
name: null,
birthdate: null
}
if (<someCheck>) {
newPerson.name = "Default name";
}
...
}
As far as JS is concerned, the above code works. However, when I incorporate TS, I get an error saying that Type 'Default name' is not assignable to type 'null'. It seems to be doing this because now TS interprets name : null to be saying that name is of type null which is not what I want. I just want to initialize it to null.
How do I get around my issue?