Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Optional Parameters and Rest Parameters section is out of date #2448

Closed
Pyrolistical opened this issue Jul 7, 2022 · 1 comment
Closed

Comments

@Pyrolistical
Copy link
Contributor

Pyrolistical commented Jul 7, 2022

Page URL: https://www.typescriptlang.org/docs/handbook/type-compatibility.html#optional-parameters-and-rest-parameters

Issue:
Now that microsoft/TypeScript#41544 has landed, the sample problem is now solvable.

// Sample problem
function invokeLater(args: any[], callback: (...args: any[]) => void) {
  /* ... Invoke callback with 'args' ... */
}

// Better solution
function invokeLater<T extends any[]>(...argsWithCallback: [...T, (...args: T) => void)]) {
  const args = argsWithCallback.slice(0, -1) as T
  const callback = argsWithCallback[argsWithCallback.length - 1] as (...args: T) => void
  /* ... Invoke callback with 'args' ... */
}

Recommended Fix:

Document feature

@typescript-bot
Copy link
Collaborator

Hello! As per #2804, we are automatically closing all open issues. Please see #2804 for a description of what issues and PRs can be accepted going forward.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants