Skip to content

Instantly share code, notes, and snippets.

@s1rat-dev
Created February 19, 2022 14:17
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 s1rat-dev/1fa4b7607cff53bc7773538dbc88637a to your computer and use it in GitHub Desktop.
Save s1rat-dev/1fa4b7607cff53bc7773538dbc88637a to your computer and use it in GitHub Desktop.
[TYPESCRIPT] Annotations for objects.
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