Created
February 19, 2022 14:17
-
-
Save s1rat-dev/1fa4b7607cff53bc7773538dbc88637a to your computer and use it in GitHub Desktop.
[TYPESCRIPT] Annotations for objects.
This file contains 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
const profile = { | |
name: 'Sırat', | |
age: 22, | |
coords: { | |
lat: 0, | |
lng: 15 | |
}, | |
setAge(age: number): void { | |
this.age = age; | |
} | |
}; | |
// const { age }: number = profile; | |
// - Doesn't work because of Destructing. | |
const { age, name }: { age: number; name: string } = profile; | |
// 'name' was also declared here. -> Just ignore! | |
const { coords: {lat,lng} }: {coords: {lat: number, lng: number}} = profile; | |
console.log(age); | |
console.log(name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment