Skip to content

Regression: Rest parameter typed as union of tuple types behaves differently in 4.3Β #44093

Closed
@dragomirtitian

Description

@dragomirtitian

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 TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions