Skip to content

Instantly share code, notes, and snippets.

@uygardev
Created September 30, 2022 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uygardev/5f36445c3a6bcc5ba9487a22cc07b389 to your computer and use it in GitHub Desktop.
Save uygardev/5f36445c3a6bcc5ba9487a22cc07b389 to your computer and use it in GitHub Desktop.
type Person = {
name: string;
surname: string
}
type Lifespan = {
birth: Date;
death: Date
}
type PersonSpan = Person | Lifespan
let o1 = {
name: "Alan",
surname: "Turing",
birth: new Date('1912/06/23'),
death: new Date('1954/06/07')
}
const ps1: PersonSpan = o1
// HATA YOK
let o2 = {
name: "Claude Elwood",
birth: new Date('1916/04/30')
}
const ps2: PersonSpan = o2
// Type '{ name: string; birth: Date; }' is not assignable to type 'PersonSpan'. Property 'death' is missing in type '{ name: string; birth: Date; }' but required in type 'Lifespan'.
let o3 = {
name: "Claude Elwood",
surname: "Shannon",
}
const ps3: PersonSpan = o3
// HATA YOK
let scientist = {
name: "Claude Elwood",
surname: "Shannon",
fields: "Mathematics and Electronic Engineering"
// "fields" property'si tip kontrolünde dikkate alınmaz
}
const person: Person = scientist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment