Skip to content

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

Open
@xiaozs

Description

@xiaozs

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]>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions