Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define 'ts-jest' property on ConfigGlobals interface in @jest/types via declaration merging #1588

Closed
G-Rath opened this issue May 2, 2020 · 2 comments 路 Fixed by #1592
Closed
Labels
馃殌 Feature Request new suggested feature

Comments

@G-Rath
Copy link
Contributor

G-Rath commented May 2, 2020

馃殌 Feature Proposal

A few months back I converted the jest ConfigGlobal type from a type to an interface to allow declaration merging, semi-specifically for ts-jest:

// 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;

....and then I never got around to opening this issue or making a PR 馃槄

Motivation

This pattern should help reduce misconfiguration issues, such as #1564 :)

Example

image

The caveat which would be useful to document is that you need to give TypeScript a reason to look in ts-jest/index.d.ts from jest.config.js. The easiest way of doing this is to import ts-jest either via jsdoc (/** @typedef {import('ts-jest')} */) or at runtime (require('ts-jest') or import 'ts-jest').

@G-Rath G-Rath added the 馃殌 Feature Request new suggested feature label May 2, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented May 2, 2020

This looks really nice, it helps #925 too. PR is welcome !

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 4, 2020

Close via #1592

@ahnpnl ahnpnl closed this as completed May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃殌 Feature Request new suggested feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants