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

TypeScript: Unable to type class constructor with destructured params #25958

Closed
warent opened this issue May 5, 2017 · 1 comment
Closed
Assignees
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@warent
Copy link

warent commented May 5, 2017

  • VSCode Version: 1.12.0
  • OS Version: OS X 10.12.4

Steps to Reproduce:

//@ts-check

class Thing {

  /**
   * @param {Object} obj
   * @param {string} obj.param
   */
  constructor({ param }) {

  }

}
//@ts-check

class Thing {

  /**
   * @param {string} param
   */
  constructor({ param }) {

  }

}

The param: string typing is not enforced or hinted

@mjbvz mjbvz self-assigned this May 5, 2017
@mjbvz mjbvz added javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code) labels May 5, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented May 5, 2017

TypeScript currently does not support the JSDoc params with properties syntax. We are tracking this here: microsoft/TypeScript#11597

One workaround is to use object literal syntax:

//@ts-check

class Thing {

  /**
   * @param {{param: string}} obj
   */
  constructor(obj) {

  }
}

new Thing({param: 3 })

This will correctly enforce the type of param

Closing as upstream

@mjbvz mjbvz closed this as completed May 5, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants