-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
tuples rest parameter regression
π Version & Regression Information
- This changed between versions 4.2 and 4.3-beta
β― Playground Link
Playground link with relevant code
π» Code
class EventEmitter<ET> {
// works with overloads
// off<K extends keyof ET>(...args: [K, unknown]): void
// off<K extends keyof ET>(...args: [K | unknown]): void
off<K extends keyof ET>(...args: [K, unknown] | [K | unknown]):void {}
}
function once<ET, T extends EventEmitter<ET>>(
emittingObject: T,
eventName: keyof ET,
callback: (event: unknown) => void,
): void {
emittingObject.off(eventName, callback); /* fails*/
// type assertion works as well
emittingObject.off(eventName as keyof ET, callback);
}
π Actual behavior
The call emittingObject.off(eventName, callback);
fails with Argument of type '[string | number | symbol, (event: unknown) => void]' is not assignable to parameter of type '[unknown] | [keyof ET, unknown]'.
π Expected behavior
The call should succeed as it did in 4.2
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue