How to add properties to an object in TypeScript

1 Answer

0 votes
const obj: Record<string, any> = {
  name: 'Tim',
};
console.log(obj);


obj.age = 51;
console.log(obj);

obj.country = 'UK';
console.log(obj);




/*
run:

{ name: 'Tim' }
{ name: 'Tim', age: 51 }
{ name: 'Tim', age: 51, country: 'UK' }

*/

 



answered Feb 25, 2022 by avibootz

Related questions

3 answers 127 views
1 answer 106 views
2 answers 265 views
1 answer 116 views
1 answer 120 views
1 answer 134 views
...