Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save charlypoly/e747fc5e7d83e180517666d73f3feb0d to your computer and use it in GitHub Desktop.
Save charlypoly/e747fc5e7d83e180517666d73f3feb0d to your computer and use it in GitHub Desktop.
TypeScript optional property (1)
interface Person {
name: string
address?: {
city: string
zipcode: string
}
}
const p: Person = { name: "John" }
p.address
// `p.address` is of type `{ city: string; zipcode: string; } | undefined`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment