Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Compile-time checking of string literal arguments based on type #394

Copy link
Copy link
Closed
@jbrantly

Description

@jbrantly
Issue body actions

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

No one assigned

    Labels

    DuplicateAn existing issue was already createdAn existing issue was already createdNeeds ProposalThis 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.SuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.