Skip to content

Target signature provides too few arguments. Expected 1 or more, but got 0 #58927

Closed as not planned
@seafronthu

Description

@seafronthu

🔎 Search Terms

ts(2345)

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 5.4.5__ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

interface RegisterFnDepINF  {
  close: Array<() => void>
  error:  Array<() => void>
  message: Array<(msg: string) => void>
  open:  Array<() => void>
}
type EventType = keyof RegisterFnDepINF
class WebSocketCommunication {
  #registerFnDep: RegisterFnDepINF = {
      close: [],
      error: [],
      message: [],
      open: []
    }
    $on<T extends EventType>(type: T, callback:  RegisterFnDepINF[T][number]) {
      this.#registerFnDep[type].push(callback)
    }
// errors
// Argument of type '(() => void) | (() => void) | ((msg: string) => void) | (() => void)' is not assignable to parameter of type '() => void'.Type '(msg: string) => void' is not assignable to type '() => void'.Target signature provides too few arguments. Expected 1 or more, but got 0.
}

🙁 Actual behavior

Argument of type '(() => void) | (() => void) | (() => void) | ((msg: string) => void)' is not assignable to parameter of type '() => void'.
Type '(msg: string) => void' is not assignable to type '() => void'.
Target signature provides too few arguments. Expected 1 or more, but got 0.

🙂 Expected behavior

not error

Additional information about the issue

interface RegisterFnDepINF  {
  close: Array<() => void>
  error:  Array<() => void>
  message: Array<(msg: string) => void>
  open:  Array<() => void>
}
type EventType = keyof RegisterFnDepINF
class WebSocketCommunication {
  #registerFnDep: RegisterFnDepINF = {
      close: [],
      error: [],
      message: [],
      open: []
    }
    $on<T extends EventType>(type: T, callback:  RegisterFnDepINF[T][number]) {
      this.#registerFnDep[type].push(callback)
    }
}

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgEoQObAM6SgMRABEIAHASQDl9lkBvAKFoQBsB7bCALmQEEoocAJ4AeABQBKZAF4AfMgBubYABNZTZNChsoPPgOHipcxcrUaAthGzY4GbvsGixF7Bh64ooDMflLV6rRspBAgevxORjJ+ZuoAvgxgQiHIAKIKoWAAKsko0sgA1hBCbDBomDh4hCQU1AyscDbIAOoQAEYAymwIRWAAwmwWFgCuIMAIcGDAbCD0GgDEUBW40NVkPOhYKwTEZFQ0+Yy0x8isHA4A2gC6ADQaJ1o6PNd3J7RWNnaXt-fHwaHPK6-BInAAkMxEWU0AA9ICAVNg0hlwDkQrIxEkQjwsjdTnAWCw2ogCnpNpVVrtavgLlkrhcQMMLG1oFcpEc3mAABY4AB0i2WVUpF0xECuPNIw2wnLEEwJRJ6EmBDDiQA
version: 5.4.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions