8000 Quick fix for 'unions can't be used in index signatures, use a mapped object type instead' · Issue #24220 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Quick fix for 'unions can't be used in index signatures, use a mapped object type instead' #24220
Closed
@DanielRosenwasser

Description

@DanielRosenwasser

The following code:

type K = "foo" | "bar";

interface SomeType {
    [prop: K]: any;
}

Gives this error message:

An index signature parameter type cannot be a union type. Consider using a mapped object type instead.

Nobody knows what mapped object types are, so let's give them a quick fix that

  • Switches the index signature to a mapped type
  • Moves other members to a separate object type that gets combined with an intersection type
  • Changes the containing object type to a type alias if the containing object type is an interface
  • Intersects with all the extends clauses if the containing object type is an interface and has any extends clauses

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Error MessagesThe issue relates to error messagingDomain: Quick FixesEditor-provided fixes, often called code actions.Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0