Hello everyone, I am looking to convert a snippet of JavaScript code into TypeScript.
JavaScript
function newState(name){
var state ={
name : name,
age : 0
}
return state
}
function initStates() {
this.JamesState = newState('James')
this.RoyState = newState('Roy');
this.RoyState.age = 20;
}
TypeScript
newPRYState(name){
let state = {
name : name,
age : 0
}
return state
}
initStates() {
this.JamesState = newState('James')
this.RoyState = newPRYState('Roy');
this.RoyState.age = 20;
}
Error: Type 'object' has no property 'age'
The desired outcome is: name: James age: 0 name: Roy age: 20
Please advise on how to resolve this issue.