Created
September 30, 2022 08:39
-
-
Save uygardev/5f36445c3a6bcc5ba9487a22cc07b389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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