Typescript error when importing jest-extended
See original GitHub issueBug
jest-extended version: 1.0.0
.ts file:
import * as matchers from "jest-extended";
I get error: File ‘…/node_modules/jest-extended/types/index.d.ts’ is not a module.
Also, after upgrading to 1.0.0 unassigned import does not work any more:
import "jest-extended";
So: Unassigned import stoped working in version 1.0.0 And wildcard import does not work in typescript because of invalid .d.ts file.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:26
- Comments:53 (12 by maintainers)
Top Results From Across the Web
TypeScript Jest imports with .js extension cause error
Everything is working fine, but when I launch my tests I get an error: Cannot find module '../models/Errors/ServerError.js' from '../src/ ...
Read more >jest-extended - npm
Start using jest-extended in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >jest-extended - npm Package Health Analysis - Snyk
The npm package jest-extended was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as...
Read more >jest-extended | Yarn - Package Manager
Problem. Jest is an amazing test runner and has some awesome assertion APIs built in by default. However, there are times when having...
Read more >Globals - Jest
The TypeScript examples from this page will only work as documented if you explicitly import Jest APIs: import {expect, jest, test} from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Had the same issue here when migrating to (ts-)jest 27 and jext-extended 1.0.0.
Before
I have in
global.d.ts
:In
jest.config.ts
:After
I just changed my
jest.config.ts
and add/all
:Everything seems to work fine with this change, like @silverwind pointed.
This was my fix:
Importing
jest-extended
is all TS needs to get it to register the types, and you only have to import it once in your project. This does not however cause anything JS-related to actually happen, and you can’t really work with the exports ofjest-extended
because they aren’t in the type defs.Importing
jest-extended/all
causes the auto-registration of all of the matchers, but doesn’t do anything types-wise. TS will allow un-typed imports like that though, since the side-effects aren’t modeled in TS’s type system.A bit of bummer to need the two imports, but it’s easier than other solutions.