microsoft / microsoft/TypeScript
An index signature parameter type with types extends string or number.
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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