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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cause ts error in jest.config.ts when import 'ts-jest' #3815

Closed
crowcc opened this issue Sep 15, 2022 · 5 comments
Closed

[Bug]: Cause ts error in jest.config.ts when import 'ts-jest' #3815

crowcc opened this issue Sep 15, 2022 · 5 comments
Labels
🐛 Bug Confirmed Bug is confirmed

Comments

@crowcc
Copy link
Contributor

crowcc commented Sep 15, 2022

Version

29.0.1

Steps to reproduce

Here's my code in jest.config.ts

import type {Config} from 'jest';
import {pathsToModuleNameMapper} from 'ts-jest';

import {compilerOptions} from './tsconfig.json';

const jestConfig: Config = {
  globals: {
    aaa: true
  }, 
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {prefix: '<rootDir>/'})
};

export default jestConfig;

Then the type declare in ts-jest causes the type of globals error:
Property ''ts-jest'' is missing in type ''{ aaa: true; }'' but required in type 'ConfigGlobals'.ts(2741)
types.d.ts(10, 13): ''ts-jest'' is declared here.

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

Expected behavior

There shouldn't be the type error when globals doesn't contain 'ts-jest' since the ts-jest config has been moved to transform.

Actual behavior

The ts type error occurs:
Property ''ts-jest'' is missing in type 'xxx'(what you write in globals) but required in type 'ConfigGlobals'.ts(2741)
types.d.ts(10, 13): ''ts-jest'' is declared here.

Debug log

Error: Jest: Failed to parse the TypeScript config file xxxxx/jest.config.ts
TSError: ⨯ Unable to compile TypeScript:
jest.config.ts:13:3 - error TS2741: Property ''ts-jest'' is missing in type '{ aaa: true; } but required in type 'ConfigGlobals'.

Additional context

No response

Environment

System:
  OS: macOS Monterey
Binaries:
  Node: 16.14.2
  pnpm: 6.24.2
npmPackages:
  jest: 29.0.1
  typescript: 4.5.4
@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 15, 2022

Did you try the import type which is recommended by our doc?

For now we can’t remove the override type of globals but it’s already marked as deprecated so you should do like documentation instead.

Or maybe marking ts-jest as optional would solve.

@crowcc
Copy link
Contributor Author

crowcc commented Sep 15, 2022

Do you mean the config type in 'ts-jest'? @ahnpnl
import type {JestConfigWithTsJest} from 'ts-jest';
I've tried, but still got the same error, and I can't set workerIdleMemoryLimit to string then

Sorry, but what do you mean by marking ts-jest as optional?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 15, 2022

If we add ? to this

'ts-jest': TsJestGlobalOptions
I think it would solve your issue.

@crowcc
Copy link
Contributor Author

crowcc commented Sep 15, 2022

Yes, so maybe I can expect a new pkg version to solve this issue?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 15, 2022

Yes:) PR is welcome to fix it

@ahnpnl ahnpnl closed this as completed in cbb88bb Sep 17, 2022
Vylpes pushed a commit to Vylpes/vylbot-app that referenced this issue May 15, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [ts-jest](https://kulshekhar.github.io/ts-jest) ([source](https://github.com/kulshekhar/ts-jest)) | dependencies | major | [`^27.1.2` -> `^29.0.0`](https://renovatebot.com/diffs/npm/ts-jest/27.1.5/29.1.0) |

---

### Release Notes

<details>
<summary>kulshekhar/ts-jest</summary>

### [`v29.1.0`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2910-httpsgithubcomkulshekharts-jestcomparev2905v2910-2023-03-26)

[Compare Source](kulshekhar/ts-jest@v29.0.5...v29.1.0)

##### Features

-   Support TypeScript 5.x ([#&#8203;4064](kulshekhar/ts-jest#4064)) ([db98cc9](kulshekhar/ts-jest@87f2782)), closes [#&#8203;4048](kulshekhar/ts-jest#4048)

#### [29.0.5](kulshekhar/ts-jest@v29.0.4...v29.0.5) (2023-01-13)

##### Reverts

-   Revert "fix(transformer): don't use cache when `tsJestConfig` is different ([#&#8203;3966](kulshekhar/ts-jest#3966))" ([185eb18](kulshekhar/ts-jest@185eb18)), closes [#&#8203;3966](kulshekhar/ts-jest#3966)

#### [29.0.4](kulshekhar/ts-jest@v29.0.3...v29.0.4) (2023-01-10)

##### Bug Fixes

-   **transformer:** don't use cache when `tsJestConfig` is different ([#&#8203;3966](kulshekhar/ts-jest#3966)) ([a445638](kulshekhar/ts-jest@a445638))
-   bump `json5` to `2.2.3` ([#&#8203;3976](kulshekhar/ts-jest#3976))

#### [29.0.3](kulshekhar/ts-jest@v29.0.2...v29.0.3) (2022-09-28)

##### Bug Fixes

-   merge config from `globals` with transformer config correctly ([#&#8203;3842](kulshekhar/ts-jest#3842)) ([9c9fd60](kulshekhar/ts-jest@9c9fd60)), closes [#&#8203;3841](kulshekhar/ts-jest#3841)
-   **presets:** allow merging transform config when using presets ([#&#8203;3833](kulshekhar/ts-jest#3833)) ([afc6a94](kulshekhar/ts-jest@afc6a94))

##### Features

-   add `useESM` option to `pathsToModuleNameMapper` options ([#&#8203;3792](kulshekhar/ts-jest#3792)) ([eabe906](kulshekhar/ts-jest@eabe906))

#### [29.0.2](kulshekhar/ts-jest@v29.0.1...v29.0.2) (2022-09-23)

##### Bug Fixes

-   mark `ts-jest` as optional in `ConfigGlobals` ([#&#8203;3816](kulshekhar/ts-jest#3816)) ([cbb88bb](kulshekhar/ts-jest@cbb88bb)), closes [#&#8203;3815](kulshekhar/ts-jest#3815)
-   use correct typings for `config:init` command ([#&#8203;3825](kulshekhar/ts-jest#3825)) ([21b94db](kulshekhar/ts-jest@21b94db))

#### [29.0.2](kulshekhar/ts-jest@v29.0.1...v29.0.2) (2022-09-22)

##### Bug Fixes

-   mark `ts-jest` as optional in `ConfigGlobals` ([#&#8203;3816](kulshekhar/ts-jest#3816)) ([cbb88bb](kulshekhar/ts-jest@cbb88bb)), closes [#&#8203;3815](kulshekhar/ts-jest#3815)

#### [29.0.1](kulshekhar/ts-jest@v29.0.0...v29.0.1) (2022-09-13)

##### Bug Fixes

-   **legacy:** include existing globals config in cached config ([#&#8203;3803](kulshekhar/ts-jest#3803)) ([e79be47](kulshekhar/ts-jest@e79be47))

##### Features

-   add typings for `ts-jest` options via `transform` config ([#&#8203;3805](kulshekhar/ts-jest#3805)) ([664b0f2](kulshekhar/ts-jest@664b0f2))

### [`v29.0.5`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2905-httpsgithubcomkulshekharts-jestcomparev2904v2905-2023-01-13)

[Compare Source](kulshekhar/ts-jest@v29.0.4...v29.0.5)

##### Reverts

-   Revert "fix(transformer): don't use cache when `tsJestConfig` is different ([#&#8203;3966](kulshekhar/ts-jest#3966))" ([185eb18](kulshekhar/ts-jest@185eb18)), closes [#&#8203;3966](kulshekhar/ts-jest#3966)

### [`v29.0.4`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2904-httpsgithubcomkulshekharts-jestcomparev2903v2904-2023-01-10)

[Compare Source](kulshekhar/ts-jest@v29.0.3...v29.0.4)

##### Bug Fixes

-   **transformer:** don't use cache when `tsJestConfig` is different ([#&#8203;3966](kulshekhar/ts-jest#3966)) ([a445638](kulshekhar/ts-jest@a445638))
-   bump `json5` to `2.2.3` ([#&#8203;3976](kulshekhar/ts-jest#3976))

### [`v29.0.3`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2903-httpsgithubcomkulshekharts-jestcomparev2902v2903-2022-09-28)

[Compare Source](kulshekhar/ts-jest@v29.0.2...v29.0.3)

##### Bug Fixes

-   merge config from `globals` with transformer config correctly ([#&#8203;3842](kulshekhar/ts-jest#3842)) ([9c9fd60](kulshekhar/ts-jest@9c9fd60)), closes [#&#8203;3841](kulshekhar/ts-jest#3841)
-   **presets:** allow merging transform config when using presets ([#&#8203;3833](kulshekhar/ts-jest#3833)) ([afc6a94](kulshekhar/ts-jest@afc6a94))

##### Features

-   add `useESM` option to `pathsToModuleNameMapper` options ([#&#8203;3792](kulshekhar/ts-jest#3792)) ([eabe906](kulshekhar/ts-jest@eabe906))

### [`v29.0.2`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2902-httpsgithubcomkulshekharts-jestcomparev2901v2902-2022-09-23)

[Compare Source](kulshekhar/ts-jest@v29.0.1...v29.0.2)

##### Bug Fixes

-   mark `ts-jest` as optional in `ConfigGlobals` ([#&#8203;3816](kulshekhar/ts-jest#3816)) ([cbb88bb](kulshekhar/ts-jest@cbb88bb)), closes [#&#8203;3815](kulshekhar/ts-jest#3815)
-   use correct typings for `config:init` command ([#&#8203;3825](kulshekhar/ts-jest#3825)) ([21b94db](kulshekhar/ts-jest@21b94db))

### [`v29.0.1`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2901-httpsgithubcomkulshekharts-jestcomparev2900v2901-2022-09-13)

[Compare Source](kulshekhar/ts-jest@v29.0.0...v29.0.1)

##### Bug Fixes

-   **legacy:** include existing globals config in cached config ([#&#8203;3803](kulshekhar/ts-jest#3803)) ([e79be47](kulshekhar/ts-jest@e79be47))

##### Features

-   add typings for `ts-jest` options via `transform` config ([#&#8203;3805](kulshekhar/ts-jest#3805)) ([664b0f2](kulshekhar/ts-jest@664b0f2))

### [`v29.0.0`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2900-httpsgithubcomkulshekharts-jestcomparev2900-next1v2900-2022-09-08)

[Compare Source](kulshekhar/ts-jest@v28.0.8...v29.0.0)

##### Features

-   drop Node 12 and Node 17 support ([#&#8203;3787](kulshekhar/ts-jest#3787)) ([0f1de16](kulshekhar/ts-jest@0f1de16))
-   migrate globals config to transformer config ([#&#8203;3780](kulshekhar/ts-jest#3780)) ([31e5843](kulshekhar/ts-jest@31e5843))
-   support Jest 29 ([#&#8203;3767](kulshekhar/ts-jest#3767)) ([94b553b](kulshekhar/ts-jest@94b553b))

##### DEPRECATIONS

-   Define `ts-jest` config under `globals` is now deprecated. Please define the config via transformer config instead.

##### BREAKING CHANGES

-   Only Node 14, 16 and 18 are supported
-   **Jest 29** is required.

### [`v28.0.8`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2808-httpsgithubcomkulshekharts-jestcomparev2807v2808-2022-08-14)

[Compare Source](kulshekhar/ts-jest@v28.0.7...v28.0.8)

##### Bug Fixes

-   allow `.mts` to be processed ([#&#8203;3713](kulshekhar/ts-jest#3713)) ([effae71](kulshekhar/ts-jest@effae71)), closes [#&#8203;3702](kulshekhar/ts-jest#3702)

### [`v28.0.7`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2807-httpsgithubcomkulshekharts-jestcomparev2806v2807-2022-07-15)

[Compare Source](kulshekhar/ts-jest@v28.0.6...v28.0.7)

##### Bug Fixes

-   update `@jest/types` to be an optional peer dependency ([#&#8203;3690](kulshekhar/ts-jest#3690)) ([8a8c3fa](kulshekhar/ts-jest@8a8c3fa)), closes [#&#8203;3689](kulshekhar/ts-jest#3689)

### [`v28.0.6`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2806-httpsgithubcomkulshekharts-jestcomparev2805v2806-2022-07-13)

[Compare Source](kulshekhar/ts-jest@v28.0.5...v28.0.6)

##### Bug Fixes

-   **config:** don't show diagnostics warning with `diagnostics: false` ([#&#8203;3647](kulshekhar/ts-jest#3647)) ([9a9bc02](kulshekhar/ts-jest@9a9bc02)), closes [#&#8203;3638](kulshekhar/ts-jest#3638)
-   **legacy:** add `useCaseSensitiveFileNames` wherever needed ([#&#8203;3683](kulshekhar/ts-jest#3683)) ([c40bc34](kulshekhar/ts-jest@c40bc34)), closes [#&#8203;3665](kulshekhar/ts-jest#3665)
-   set `@jest/types` as peer dependency ([#&#8203;3633](kulshekhar/ts-jest#3633)) ([24567e1](kulshekhar/ts-jest@24567e1))

### [`v28.0.5`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2805-httpsgithubcomkulshekharts-jestcomparev2804v2805-2022-06-11)

[Compare Source](kulshekhar/ts-jest@v28.0.4...v28.0.5)

##### Bug Fixes

-   **legacy:** throw type check error in ESM mode with `reject` ([#&#8203;3618](kulshekhar/ts-jest#3618)) ([7dd01ff](kulshekhar/ts-jest@7dd01ff)), closes [#&#8203;3507](kulshekhar/ts-jest#3507)

### [`v28.0.4`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2804-httpsgithubcomkulshekharts-jestcomparev2803v2804-2022-06-02)

[Compare Source](kulshekhar/ts-jest@v28.0.3...v28.0.4)

##### Bug Fixes

-   remove `@types/jest` from peer deps ([#&#8203;3592](kulshekhar/ts-jest#3592)) ([b66b656](kulshekhar/ts-jest@b66b656))

### [`v28.0.3`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2803-httpsgithubcomkulshekharts-jestcomparev2802v2803-2022-05-23)

[Compare Source](kulshekhar/ts-jest@v28.0.2...v28.0.3)

##### Bug Fixes

-   **security:** update version of `json5` ([#&#8203;3528](kulshekhar/ts-jest#3528)) ([b31f5ba](kulshekhar/ts-jest@b31f5ba))

### [`v28.0.2`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2802-httpsgithubcomkulshekharts-jestcomparev2801v2802-2022-05-07)

[Compare Source](kulshekhar/ts-jest@v28.0.1...v28.0.2)

##### Bug Fixes

-   **transformers:** use `Array.sort` in hoisting transformer ([#&#8203;3498](kulshekhar/ts-jest#3498)) ([e400a6e](kulshekhar/ts-jest@e400a6e)), closes [#&#8203;3476](kulshekhar/ts-jest#3476)

### [`v28.0.1`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2801-httpsgithubcomkulshekharts-jestcomparev2800v2801-2022-05-03)

[Compare Source](kulshekhar/ts-jest@v28.0.0...v28.0.1)

##### Bug Fixes

-   lower the required node version to ^16.10 ([#&#8203;3495](kulshekhar/ts-jest#3495)) ([3a4e48a](kulshekhar/ts-jest@3a4e48a)), closes [#&#8203;3494](kulshekhar/ts-jest#3494)

### [`v28.0.0`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#&#8203;2800-httpsgithubcomkulshekharts-jestcomparev2800-next3v2800-2022-05-02)

[Compare Source](kulshekhar/ts-jest@v27.1.5...v28.0.0)

##### Bug Fixes

-   **legacy** invoke Babel `processAsync` for `babel-jest` in ESM mode instead of `process` ([#&#8203;3430](kulshekhar/ts-jest#3430)) ([0d7356c](kulshekhar/ts-jest@0d7356c))

##### Features

-   **presets:** add presets for legacy mode ([#&#8203;3465](kulshekhar/ts-jest#3465)) ([543b4ad](kulshekhar/ts-jest@543b4ad))
-   mark `ConfigSet` as legacy ([#&#8203;3456](kulshekhar/ts-jest#3456)) ([a986729](kulshekhar/ts-jest@a986729))
-   mark `TsCompiler` and `TsJestCompiler` as legacy ([#&#8203;3457](kulshekhar/ts-jest#3457)) ([0f2fe30](kulshekhar/ts-jest@0f2fe30))
-   remove `path-mapping` AST transformer ([#&#8203;3455](kulshekhar/ts-jest#3455)) ([f566869](kulshekhar/ts-jest@f566869))
-   set Jest peer dependencies to v28 ([#&#8203;3454](kulshekhar/ts-jest#3454)) ([1e880ff](kulshekhar/ts-jest@1e880ff))
-   **core:** drop support for Node.js 10 ([#&#8203;3332](kulshekhar/ts-jest#3332)) ([7a9aa61](kulshekhar/ts-jest@7a9aa61))
-   **core:** remove `mocked` testing util ([#&#8203;3333](kulshekhar/ts-jest#3333)) ([2d9017d](kulshekhar/ts-jest@2d9017d))
-   **core:** remove `ts-jest/utils` sub path export ([#&#8203;3334](kulshekhar/ts-jest#3334)) ([9f253d3](kulshekhar/ts-jest@9f253d3))
-   mark `TsJestTransformer` as legacy ([#&#8203;3451](kulshekhar/ts-jest#3451)) ([b090179](kulshekhar/ts-jest@b090179))

##### BREAKING CHANGES

-   `path-mapping` AST transformer is no longer shipped in `ts-jest` v28. Please use an alternative one like https://github.com/LeDDGroup/typescript-transform-paths instead.
-   Any imports `ts-jest/dist/compiler/ts-compiler` should change to `ts-jest/dist/legacy/compiler/ts-compiler`
-   Any imports `ts-jest/dist/compiler/ts-jest-compiler` should change to `ts-jest/dist/legacy/compiler/ts-jest-compiler`
-   Any imports `ts-jest/dist/config/config-set` should change to `ts-jest/dist/legacy/config/config-set`
-   Minimum support `TypeScript` version is now **4.3** since Jest 28 requires it.
-   **Jest 28** is required.
-   **core:** Any imports `ts-jest/utils` should be replaced with `ts-jest`.
-   **core:** Starting from Jest 27.4, `mocked` has been integrated into Jest repo.
-   **core:** Support for Node.js v10 has been removed as Jest drops support for it.

#### [27.1.5](kulshekhar/ts-jest@v27.1.3...v27.1.4) (2022-05-17)

##### Bug Fixes

-   **transformers** use `Array.sort` in hoisting transformer ([#&#8203;3498](kulshekhar/ts-jest#3498)) ([e400a6e](kulshekhar/ts-jest@e400a6e)), fixes [#&#8203;3476](kulshekhar/ts-jest#3476)

#### [27.1.4](kulshekhar/ts-jest@v27.1.3...v27.1.4) (2022-03-24)

##### Bug Fixes

-   **compiler:** revert [#&#8203;3194](kulshekhar/ts-jest#3194) ([#&#8203;3362](kulshekhar/ts-jest#3362)) ([2b7dffe](kulshekhar/ts-jest@2b7dffe)), closes [#&#8203;3272](kulshekhar/ts-jest#3272)
-   remove `esbuild` from peer dependency ([#&#8203;3360](kulshekhar/ts-jest#3360)) ([8c8c1ca](kulshekhar/ts-jest@8c8c1ca)), closes [#&#8203;3346](kulshekhar/ts-jest#3346)
-   support Babel config file with `.cjs` extension ([#&#8203;3361](kulshekhar/ts-jest#3361)) ([5e5ac4a](kulshekhar/ts-jest@5e5ac4a)), closes [#&#8203;3335](kulshekhar/ts-jest#3335)

#### [27.1.3](kulshekhar/ts-jest@v27.1.2...v27.1.3) (2022-01-14)

##### Bug Fixes

-   **compiler:** update memory cache for compiler using received file content ([#&#8203;3194](kulshekhar/ts-jest#3194)) ([e4d9541](kulshekhar/ts-jest@e4d9541))

#### [27.1.2](kulshekhar/ts-jest@v27.1.1...v27.1.2) (2021-12-15)

##### Bug Fixes

-   stimulate `esbuild` type to avoid importing `esbuild` directly ([#&#8203;3147](kulshekhar/ts-jest#3147)) ([9ace0a9](kulshekhar/ts-jest@9ace0a9))

#### [27.1.1](kulshekhar/ts-jest@v27.1.0...v27.1.1) (2021-12-07)

##### Bug Fixes

-   bring back `afterProcess` hook ([#&#8203;3132](kulshekhar/ts-jest#3132)) ([2b6b86e](kulshekhar/ts-jest@2b6b86e))
-   make `esbuild` as optional peer dependency ([#&#8203;3129](kulshekhar/ts-jest#3129)) ([20258de](kulshekhar/ts-jest@20258de))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

 **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC43NC4yIiwidXBkYXRlZEluVmVyIjoiMzQuNzQuMiJ9-->

Co-authored-by: Renovate Bot <renovate@vylpes.com>
Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/244
Co-authored-by: RenovateBot <renovate@vylpes.com>
Co-committed-by: RenovateBot <renovate@vylpes.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Confirmed Bug is confirmed
Projects
None yet
Development

No branches or pull requests

2 participants