Skip to content

JSDoc: inference and type checking breaks when param is destructured #16219

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

Closed
OliverJAsh opened this issue Jun 2, 2017 · 4 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue VS Code Tracked There is a VS Code equivalent to this issue

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jun 2, 2017

TypeScript Version: 2.3.4

Code

This works:

{
  /**
   * @typedef {{
      type: string,
      color?: string
    }} Props
  * @param {Props} props
  */
  const foo = (props) => {
    console.log(props.type); // type of type is string
  };
  foo({ type: 1 }); // error

  // However, if I destructure the param, it breaks:

  /**
   * @typedef {{
      type: string,
      color?: string
    }} Props2
  * @param {Props2} props
  */
  const foo2 = ({ type }) => {
    console.log(type); // type of type is any, expected string
  };
  foo2({ type: 1 }); // expected error but got none
}

Reading through the docs on JSDoc support, I couldn't find anything to suggest why this shouldn't work.

@OliverJAsh
Copy link
Contributor Author

Possibly related to #11859

@OliverJAsh OliverJAsh changed the title JSDoc types break when param is destructured JSDoc: inference breaks when param is destructured Jun 2, 2017
@OliverJAsh OliverJAsh changed the title JSDoc: inference breaks when param is destructured JSDoc: inference and type checking breaks when param is destructured Jun 2, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 23, 2017

should be covered by #11859, though i think the syntax in jsdoc comments in this report are the correct ones.

@mhegazy mhegazy added Duplicate An existing issue was already created Bug A bug in TypeScript and removed Duplicate An existing issue was already created labels Aug 23, 2017
@mhegazy mhegazy added Salsa Domain: JSDoc Relates to JSDoc parsing and type generation labels Aug 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 23, 2017

on a second thought, should keep them separate, the two scenarios are different enough that we may want to fix one and not the other.

@mjbvz mjbvz added the VS Code Tracked There is a VS Code equivalent to this issue label Jan 19, 2018
@mhegazy mhegazy added this to the Future milestone Apr 12, 2018
@sandersn
Copy link
Member

Fixed, I believe by #23307

@sandersn sandersn added the Fixed A PR has been merged for this issue label Jun 11, 2018
@mhegazy mhegazy modified the milestones: Future, TypeScript 3.0 Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

4 participants