Skip to content

JSDocs @typedef {typeof import()} doesn't work with @ts-check pragma (throws "not a module") #25480

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
donaldpipowitch opened this issue Jul 6, 2018 · 3 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@donaldpipowitch
Copy link
Contributor

donaldpipowitch commented Jul 6, 2018

TypeScript Version: 3.0.0-dev.201xxxxx and 2.9.2

Search Terms:

  • JSDoc
  • typedef
  • import
  • ts-check

Code

Having jest and @types/jest installed this snippet...

/** @typedef {typeof import('jest')} */

/** @type jest.InitialConfig */
const config = {
  collectCoverage: true,
  coverageReporters: ['text'],
  transform: {
    '^.+\\.(ts?|tsx?)$': '<rootDir>/node_modules/ts-jest/preprocessor.js'
  },
  testRegex: '(/tests/.*)\\.unit\\.(ts?|tsx?)$',
  testPathIgnorePatterns: ['/node_modules/', '/tests/helper/'],
  moduleFileExtensions: ['ts', 'tsx', 'json', 'js']
};

module.exports = config;

...seems to correctly use ProjectConfig. But when I add // @ts-check in the first line I get an error.

Expected behavior:

No error. Just more type checks. (E.g. // @ts-check I could set collectCoverage: 'foo' without an error.)

Actual behavior:

/** @typedef {typeof import('jest')} */: File '../node_ modules/@types/jest/index.d.ts' is not a module.

Related Issues:

@mhegazy
Copy link
Contributor

mhegazy commented Jul 6, 2018

the file @types/jest/index.d.ts is not a module. that can be a .d.ts error that can be fixed by sending a PR to DT. jest is defined as a global namespace.

@mhegazy mhegazy added the External Relates to another program, environment, or user action which we cannot control. label Jul 6, 2018
@donaldpipowitch
Copy link
Contributor Author

Thank you for the fast response!

@donaldpipowitch
Copy link
Contributor Author

Looks like I need to write this:

// @ts-check

/** @type {jest.InitialOptions} */
const config = {};

module.exports = config;

This already works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants