microsoft / microsoft/TypeScript

An index signature parameter type with types extends string or number.

Open
#28,519 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

An_index_signature_parameter_type_must_be_string_or_number_1023:
with this Feature, I can't make this code work:

export class Events<ED extends EventsDef, EventName extends keyof ED = keyof ED> {
    private eventMap = new Map<EventName, Event<ED[EventName]>>();

    constructor() {
        new Proxy(this, {
            get: (target, p) => {
                if (p in target) {
                    return target[p];
                } else {
                    this.getEvent(p as EventName);
                }
            }
        })
    }

    private getEvent(eventName: EventName) {
        return this.eventMap.get(eventName) || this.generateEvent(eventName);
    }

    private generateEvent(eventName: EventName) {
        let event = new Event<ED[EventName]>();
        this.eventMap.set(eventName, event);
        return event;
    }

                     // error here
    readonly [eventName: EventName]: Event<ED[EventName]>;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducing TypeScript snippet and the diagnostic “An index signature parameter type must be string or number” in this issue. Trace how the typechecker handles the generic EventName index signature, then establish the intended behavior and add coverage showing when this form should be accepted or rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.