Closed
Description
Often a method will take as a string the name of a property of some object that it's working on. A common example would be http://backbonejs.org/#Model-get
It would be ideal if TypeScript could provide compile-time checking on these calls to make sure that the string is actually a valid property of the underlying model. As a possible proposal:
interface Person {
firstName: string
lastName: string
phoneNumber: string
}
function get(property: memberof Person) {}
get('firstName') // compiles
get('middleName') // would not compile
In the context of the get function, "memberof Person" would be equivalent to "string".