Skip to content

[JSDoc/checkjs]: exported @typedef doesn't work with mapped types directly #24916

@Hotell

Description

@Hotell

TypeScript Version: 2.9.1

Search Terms:

  • checkJS
  • JSDoc

Expected behavior:
following should work without errors:

  • types.js
// @ts-check
export {}

/**
 * @typedef {Partial<{one:boolean} & {two:string}>} Test
 */
  • index.js
// @ts-check
/**
 * @type {import('./types').Test}
 */
const test = {}

Actual behavior:

  • types.js
// @ts-check
export {}

/**
 * @typedef {Partial<{one:boolean} & {two:string}>} Test
 */
  • index.js
// @ts-check
/**
 * @type {import('./types').Test}
 */
const test = {}

exported @typedef definitions, which are using Mapped types transformations (Partial,...), will error out with cryptic error when they are imported via /** @type {import('./types).MappedTest}* to annotate a variable :

image

Although creating a variable which is typed via mapped type and exported as a token value works:

  • types.js
// @ts-check
export {}

/**
 * @typedef {Partial<{one:boolean} & {two:string}>} Test
 */

/**
 * @type {Test}
 */
export var Test
  • index.js
// @ts-check
/**
 * @type {typeof import('./types').Test}
 */
const test = {}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions