Skip to content

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

Closed
@OliverJAsh

Description

@OliverJAsh

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationFixedA PR has been merged for this issueVS Code TrackedThere is a VS Code equivalent to this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions