Skip to content

[3.2.0-rc] .bind with overloads causes compile error in strict mode (strictBindCallApply) #28582

Closed
@eamodio

Description

@eamodio

TypeScript Version: 3.2.0-rc

Search Terms:
strictBindCallApply, bind, overload

Code

class Logger {
  static debug(message: string, ...params: any[]): void;
  static debug(context: object | undefined, message: string, ...params: any[]): void;
  static debug(contextOrMessage: object | string | undefined, ...params: any[]): void {
    // ...
  }

  static log(message: string, ...params: any[]): void;
  static log(context: object | undefined, message: string, ...params: any[]): void;
  static log(contextOrMessage: object | string | undefined, ...params: any[]): void {
    // ...
  }
}

// @log decorator
function log(debug: boolean) {
  // ...
  const logFn = debug ? Logger.debug.bind(Logger) : Logger.log.bind(Logger);

  // ...

  // Errors with Argument of type 'string' is not assignable to parameter of type 'object | undefined'
  // NOTE: This doesn't error without the .bind() call above
  logFn("message", 1, 2, 3);
}

Expected behavior:

Not exactly sure, but not an error

Actual behavior:

Error -- see playground link

Playground Link:

http://www.typescriptlang.org/play/index.html#src=class%20Logger%20%7B%0D%0A%20%20static%20debug(message%3A%20string%2C%20...params%3A%20any%5B%5D)%3A%20void%3B%0D%0A%20%20static%20debug(context%3A%20object%20%7C%20undefined%2C%20message%3A%20string%2C%20...params%3A%20any%5B%5D)%3A%20void%3B%0D%0A%20%20static%20debug(contextOrMessage%3A%20object%20%7C%20string%20%7C%20undefined%2C%20...params%3A%20any%5B%5D)%3A%20void%20%7B%0D%0A%20%20%20%20%2F%2F%20...%0D%0A%20%20%7D%0D%0A%0D%0A%20%20static%20log(message%3A%20string%2C%20...params%3A%20any%5B%5D)%3A%20void%3B%0D%0A%20%20static%20log(context%3A%20object%20%7C%20undefined%2C%20message%3A%20string%2C%20...params%3A%20any%5B%5D)%3A%20void%3B%0D%0A%20%20static%20log(contextOrMessage%3A%20object%20%7C%20string%20%7C%20undefined%2C%20...params%3A%20any%5B%5D)%3A%20void%20%7B%0D%0A%20%20%20%20%2F%2F%20...%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0A%2F%2F%20%40log%20decorator%0D%0Afunction%20log(debug%3A%20boolean)%20%7B%0D%0A%20%20%2F%2F%20...%0D%0A%20%20const%20logFn%20%3D%20debug%20%3F%20Logger.debug.bind(Logger)%20%3A%20Logger.log.bind(Logger)%3B%0D%0A%0D%0A%20%20%2F%2F%20...%0D%0A%0D%0A%20%20%2F%2F%20Errors%20with%20Argument%20of%20type%20'string'%20is%20not%20assignable%20to%20parameter%20of%20type%20'object%20%7C%20undefined'%0D%0A%20%20%2F%2F%20NOTE%3A%20This%20doesn't%20error%20without%20the%20.bind()%20call%20above%0D%0A%20%20logFn(%22message%22%2C%201%2C%202%2C%203)%3B%0D%0A%7D

Related Issues:
#28567

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixedFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions