Typescript: JSDoc not recognized for default export expressions

Created on 10 May 2018  路  6Comments  路  Source: microsoft/TypeScript


TypeScript Version: 2.8.3


Search Terms:
jsdoc default export expression type

Code

import webpack from 'webpack';

//  works
/** @type {webpack.Configuration[]} */
const foo = [ {}, {} ]; // has correct type

/** @type {webpack.Configuration[]} */
export default [ {}, {} ]; // has wrong type

/** @export {webpack.Configuration[]} */
export default [ {}, {} ]; // has wrong type

/** @exports {webpack.Configuration[]} */
export default [ {}, {} ]; // has wrong type

Expected behavior:
JSDoc type information is used.

Actual behavior:
JSDoc type information is not used.

Playground Link: n/a

Related Issues: none

Bug JSDoc JavaScript Moderate help wanted

All 6 comments

I would say this is the correct form

/** @type {webpack.Configuration[]} */
export default [ {}, {} ]; // has wrong type

meanwhile as a workaround, you can use cast syntax:

```ts
export default /** @type {webpack.Configuration[]} */([{}, {}]);
````

Also impacted by this! I'm super new to TypeScript (only really use JSDoc within VS Code) but thought I'd poke around this issue a bit - I'm a little unsure of where to put an example test though. Is this the correct location / test style?

TypeScript\tests\cases\conformance\jsdoc\jsdocTypeTagExport.ts

// @allowJS: true
// @suppressOutputPathCheck: true
// @strictNullChecks: true

// @filename: a.js
/** @type {(key: string) => string} */
export default (key) => key;

// @filename: b.ts
export default (key: string) => string;

@IanMitchell You also need // @checkJs: true but otherwise you've got it.

@mhegazy workaround works.

export default /** @type {webpack.Configuration[]} */([{}, {}]);  // OK

but the desired syntax does not

/** @type {webpack.Configuration[]} */
export default [{}, {}]); // Wrong

any Roadmap?

Export default doesn't work again. In-lining the type doesn't fix it.
Peek 2020-11-08 15-06

It's hitting me too.

VSCode export default type issue

I'm running a Vue2 application with JavaScript. No typescript is involved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  路  3Comments

wmaurer picture wmaurer  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

jbondc picture jbondc  路  3Comments