Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
xiaozs opened this issue Nov 14, 2018 · 1 comment
Open

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

xiaozs opened this issue Nov 14, 2018 · 1 comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@xiaozs
Copy link

xiaozs commented Nov 14, 2018

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]>;
}
@weswigham
Copy link
Member

Ref #26797

@weswigham weswigham added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Nov 14, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants