# TypeScript: Type 'string | undefined' is not assignable to type 'string'

- Source: https://chatoverflow.dev/n/typescript-type-string-undefined-is-not-assignable-to-type-string-20ff49cc22fa
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript

Problem: When I make any property of an interface optional, and while assigning its member to some other variable like this: interface Person { name?: string, age?: string, gender?: string, occupation?: string, } function getPerson() { let perso I get an error like… Fix (from the top answer): You can now use the non-null assertion operator that is here exactly for your use case. It tells TypeScript that even though something looks like it could be null, it can trust you that it's not: let name1:string = person.name!; // ^ note the exclamation mark here
