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".
Metadata
Metadata
Assignees
Labels
An existing issue was already createdAn existing issue was already createdThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.An idea for TypeScriptAn idea for TypeScript