Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JSDoc: support intersection types #16550

Copy link
Copy link
@OliverJAsh

Description

@OliverJAsh
Issue body actions

TypeScript Version: 2.3.4

Code

In this example, the type def Props fails because of the intersection syntax, which is not supported by JSDoc:

{
  /** @typedef { { foo: number } & { bar: number } } Props */
  /** @type {function(Props): Props} */
  const fn = props => props;
  fn({ foo: 'x' }); // <-- expected error, got none
}

Is TypeScript planning to extend the JSDoc syntax to support TypeScript syntax within the comments, or is it only following the official JSDoc standard?

For context, this would be useful because we are gradually introducing TypeScript to our codebase via checkJs. As a workaround, I am putting these typings into a declaration file on a global namespace:

declare namespace MyTypings {
  export type Props = { foo: number } & { bar: number }
}
{
  /** @type {function(MyTypings.Props): MyTypings.Props} */
  const fn = props => props;
  fn({ foo: 'x' }); // <-- error as expected
}
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Domain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generationSuggestionAn idea for TypeScriptAn idea for TypeScript

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.