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

Provide a way to indicate that a function declaration conforms to some interface/type #40455

Closed
dinofx opened this issue Sep 9, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@dinofx
Copy link

dinofx commented Sep 9, 2020

When using jsdoc, you can do something like:

/**
 * @typedef {(path: string[], line: number) => void} PathHandler
 */

/** @type {PathHandler} */
function handlePath(path, lineNumber) {
  //TODO
}

This indicates that the type of handlePath is determined by PathHandler. The types for params path and lineNumber are resolved accordingly.

When converting this code to typescript, there is no way to associate the function declaration with the new type/interface. One workaround is just to repeat all of the type information from PathHandler at every function that conforms to the type. Another workaround is to use a function expression, like const handlePath: PathHandler = function(....), but this loses hoisting and unnecessarily imposes one style over another.

There should be a way to type the entire function declaration similar to the jsdoc equivalent, e.g.:

function:PathHandler handlePath(path, lineNumber) {
  //TODO
}
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 9, 2020
@RyanCavanaugh
Copy link
Member

Duplicate #22063

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants