You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When object is annotated with following definition:
interface Person {
"Id": number
"First Name": string,
"Last Name": string,
}
I would like to access the "First Name" and "Last Name" properties in type safe manner.
var person : Person = { Id: 5, "First Name": "Lorem", "Last Name": "Ipsum" };
var firstName = person["First Name"]; //this is neither validated by compiler nor I get auto completion for the properties
var _undefined = person["undefined"]; //compiler does not complain.
similarly:
person["First Name"] = "Lorem"; //this is neither validated by compiler nor I get auto completion for the properties
person["undefined"] = "Ipsum"; //compiler does not complain.
I have tried experimenting with restricting index signature type:
When object is annotated with following definition:
I would like to access the "First Name" and "Last Name" properties in type safe manner.
similarly:
I have tried experimenting with restricting index signature type:
however, it compiler complains: