Skip to content

export default can not be typed via jsdocΒ #45233

Closed
@daKmoR

Description

@daKmoR

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about jsdoc and export default

⏯ Playground Link

/**
 * The complete Triforce, or one or more components of the Triforce.
 * 
 * @typedef {Object} WishGranter
 * @property {boolean} hasCourage - Indicates whether the Courage component is present.
 * @property {boolean} hasPower - Indicates whether the Power component is present.
 * @property {boolean} hasWisdom - Indicates whether the Wisdom component is present.
 */

/** @type {WishGranter} */
const works = {
  hasCourage: true,
  foo: false // correctly errors
}

// does not work for export default

/** @type {WishGranter} */
export default {
  hasCourage: true,
  foo: false // no error
}

// workaround that "breaks" prettier e.g. you can't format anymore as it will remove the `()`
// https://github.com/prettier/prettier/issues/11279

///** @type {WishGranter} */
//export default ({
//  // type RocketCliConfig
//});
Compiler Options
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "checkJs": true,
    "allowJs": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

πŸ’» Code

/** @type {import('rocket/cli').RocketCliConfig} */
export default {
  // "no" type - e.g. any
} 

πŸ™ Actual behavior

It does not put any type for export default.

πŸ™‚ Expected behavior

/** @type {import('rocket/cli').RocketCliConfig} */
export default {
  // type RocketCliConfig
} 

πŸ˜… Workaround

A possible workaround is to typecast via () but that "breaks" prettier as it will always remove it as "usless" brackets.
See prettier/prettier#11279

/** @type {import('rocket/cli').RocketCliConfig} */
export default ({
  // type RocketCliConfig
})

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions