Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Document the "official" type for what should be exported from jest.config.js #9529

Closed
G-Rath opened this issue Feb 7, 2020 · 5 comments
Closed

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Feb 7, 2020

🚀 Feature Proposal

I feel a bit foolish asking this as in theory it should be somewhat obvious & easy...., but I can't figure out what type to use for the export of jest.config.js for TypeScript(-in-js) 😬

i.e with .eslintrc.js I can do:

/** @type {import('eslint').Linter.Config} */
const config = {
  ...
}

module.exports = config;

But for Jest theres a couple of different interfaces, each with their pros and cons: there's Project & Global, some with required properties, and others all optional, and then theres the normalised values...

I think it would be good to mark a type/interface as The Public Configuration Type, and put a line on the Configuring Jest page.

Motivation

This would let us be nice and type safe when configuring jest :D
It would also mean we'd not be having to use external schemas that need to be updated by third-parties.

Example

/** @type {import('jest-package').Config} */
const config = {
  ...
}

module.exports = config;

Pitch

Because it's already in the core... somewhere... 🕵

@SimenB
Copy link
Member

SimenB commented Feb 7, 2020

In theory it's import('@jest/types').Config.InitialOptions. I don't know how well it works out in practice to use it though, it's designed for internal usage

@G-Rath
Copy link
Contributor Author

G-Rath commented Feb 7, 2020

@SimenB that seems to work pretty well.

One thing of note: ConfigGlobals is defined as a type of Record<string, any>, which means we can't use declaration merging to supplement it.

i.e ts-jest could merged its config into globals if ConfigGlobals was an interface, like so:

// ts-jest/index.d.ts
declare module '@jest/types' {
  namespace Config {
    interface ConfigGlobals {
      'ts-jest': TsJestGlobalOptions;
    }
  }
}

// jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
const config= {
  globals: {
    'ts-jest': {
      isolatedModules: true,
      myProperty: 1 // error, "myProperty" is not defined!
    }
  }
}

module.exports = config;

Would it be alright if I opened a PR changing this?

@SimenB
Copy link
Member

SimenB commented Feb 8, 2020

Yeah, sure 👍

@SimenB
Copy link
Member

SimenB commented Oct 22, 2020

@G-Rath close this?

@SimenB SimenB closed this as completed Oct 15, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

2 participants