Skip to content

Optional index signature #7118

Description

@Pajn

It should be possible to make the index signature optional like this:
export type Actions = {[type: string]?: Action}

If the index signature is not optional (as I'm required to type right now) I get errors when passing parameters with the Actions type as the index signature is missing in the passed object.

Activity

  1. mhegazy commented on Feb 17, 2016

    @mhegazy
    Contributor

    An index signature is a "constraint" on a type; i do not understand what an optional constraint means..

    Can you elaborate on your case, and what you are trying to achieve here.

    In your example, all properties should be Action; and if not, what should they be? why not define the index signature in a more permissive fashion, i.e [type:string]: any or [type:string]:Action|Person|Entity?

  2. Pajn commented on Feb 17, 2016

    @Pajn
    Author

    I currently get the error "Index signature is missing in type", what I want to constrain is that all values are Action, not that the passed object allows setting additional keys

  3. RyanCavanaugh commented on Feb 17, 2016

    @RyanCavanaugh
    Member

    If your use case isn't solved by #7029, please post some code so we can understand the scenario. Thanks!

  4. Pajn commented on Feb 17, 2016

    @Pajn
    Author

    Oh, sorry. Didn't look for already fixed issues, just open :/

  5. added
    ExternalRelates to another program, environment, or user action which we cannot control.
    and removed
    Needs More InfoThe issue still hasn't been fully clarified
    on Feb 17, 2016
  6. locked and limited conversation to collaborators on Jun 19, 2018
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

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions