You trying to set variable name1
, witch type set as strict string (it MUST be string) with value from object field name
, witch value type set as optional string (it can be string or undefined, because of question sign). If you really need this behavior, you have to change type of name1
like this:
let name1: string | undefined = person.name;
And it'll be ok;