Skip to content

JSDoc: support intersection types #16550

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 15, 2017 · 1 comment · Fixed by #17176
Closed

JSDoc: support intersection types #16550

OliverJAsh opened this issue Jun 15, 2017 · 1 comment · Fixed by #17176
Assignees
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jun 15, 2017

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
}
@yuit yuit added Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript labels Jun 15, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Jun 15, 2017

@sandersn, we should make sure we support the full list of options here, i.e intersection, typeof, call and construct signatures, etc..

@mhegazy mhegazy added this to the TypeScript 2.5 milestone Jun 15, 2017
@mhegazy mhegazy added the Salsa label Jun 15, 2017
sandersn added a commit that referenced this issue Jul 13, 2017
This means that JSDoc types can include the full range of Typescript
types now. It also means that Typescript annotations can include JSDoc
types. This is disallowed with a new error, however. But Typescript can
still give the correct types to JSDoc that shows up in .ts files by
mistake. This can easily happen, for example with types like

```ts
var x: number? = null;
var y: ?string = null;
var z: function(string,string): string = (s,t) => s + t;

// less likely to show up, but still understood.
var ka: ? = 1;
```

In the future, I will add a quick fix to convert these into the correct
types.

Fixes #16550
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants