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]: breaking behavior for TypeScript globals compared to the DefinitelyTyped counterpart #12853

Closed
noomorph opened this issue May 16, 2022 · 3 comments

Comments

@noomorph
Copy link
Contributor

Version

28.1.0

Steps to reproduce

  1. Clone my repo from: https://github.com/noomorph/tsc-jest-28-issue
  2. Follow the README there.

Expected behavior

I expect that importing @jest/globals would indeed add common things like describe, it, test, beforeEach, etc. to the global scope, so I don't have to import them every time explicitly:

import { describe, it, expect } from '@jest/globals';

Actual behavior

I'm seeing TSC errors like these on an attempt to compile my test suites:

globals.test.ts(1,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
globals.test.ts(2,3): error TS2304: Cannot find name 'beforeEach'.
globals.test.ts(6,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.

Additional context

No response

Environment

System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  npmPackages:
    jest: ^28.1.0 => 28.1.0
@ahnpnl
Copy link
Contributor

ahnpnl commented May 16, 2022

I think a solution to go is doing like vitest, see my comment kulshekhar/ts-jest#3513 (comment)

@SimenB
Copy link
Member

SimenB commented May 16, 2022

Global types are not defined by any modules in this repo, they are in DT. (I realize the name of the module in Jest is bad).

@ahnpnl seems somewhat reasonable way of opting into global types. We don't have global types in this repo tho. Might make sense to add in the same way, but that's separate from this issue. Could you open up a feature request for it instead?

@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 Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants