Skip to content

Allow type casts around shorthand property names #13035

Description

Is there any reason shorthand property names ({ a }, etc.) don't allow type casting around the names? It would be a mildly useful feature.

Code

The following object literals are all intended to compile to { foo: foo }:

function take(arg: { foo: string }) { }

let foo: string;

// Allowed
take({ foo });
take({ foo: foo });
take({ foo: foo as string });
take({ foo: <string>foo });

// Syntax errors
take({ <string>foo });
take({ foo as string });

Expected behavior:
These should all compile to the same thing.

Actual behavior:
The lines with type casting in the names are syntax errors.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions