ts-jest
ts-jest copied to clipboard
[Bug]: Import issue when using "Satisfies" keyword
Version
29.1.0
Steps to reproduce
My repository is private, I tried to reproduce on an example repo but I couldn't.
My bug is the following, I have 3 files
aFunction.spec.ts // testing aFunction.ts
aFunction.ts // importing model.ts
model.ts
With the following content
// in aFunction.spec.ts
import { aFunction } from './aFunction';
test('bug class undefined when using satisifies', () => {
const method = aFunction(['a']);
expect(() => method).toThrow();
});
// in aFunction.ts
import { create, ReturnType } from './model';
export function aFunction(names: string[] | undefined) {
return {
experiences: names?.map((name) =>
create({
name: name,
}),
),
} satisfies ReturnType;
}
// in model.ts
interface Props {
name: string;
}
export type ReturnType = {
experiences?: Props[];
};
export function create(props: Props) {
return { name: props.name };
}
When I run yarn jest
I've got the following error ReferenceError: model_1 is not defined
But the error disappear in one of the following cases:
- When I remove
satisfies ReturnType
inaFunction.ts
- When I first create
const experiences = names?.map(...)
and then returnsreturn {experiences} satisfies ReturnType
- When I remove
isolatedModules: true
in myjest.config.ts
Expected behavior
imports from 'model' are indeed imported
Actual behavior
ReferenceError
Debug log
Additional context
// Jest.config.ts
import type { Config } from '@jest/types';
export default async (): Promise<Config.InitialOptions> => {
return {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '(?<!e2e|matching).spec.ts$',
transform: {
'^.+\\.(t|j)s$': [
'ts-jest',
{
isolatedModules: true, // The following line improves perf : https://huafu.github.io/ts-jest/user/config/isolatedModules
},
],
},
}
}
maybe useful packages version
- "ts-node": "^10.9.1",
- "typescript": "^4.9.3"
- "jest": "^29.3.1"
- "ts-jest": "^29.1.0",
Environment
System:
OS: macOS 13.2.1
CPU: (8) arm64 Apple M1 Pro
Binaries:
Node: 18.9.0 - /var/folders/rb/7gpds4dj163b0g71gyr42brh0000gn/T/fnm_multishells/20546_1681215510586/bin/node
Yarn: 1.22.19 - /var/folders/rb/7gpds4dj163b0g71gyr42brh0000gn/T/fnm_multishells/20546_1681215510586/bin/yarn
npm: 8.19.2 - /var/folders/rb/7gpds4dj163b0g71gyr42brh0000gn/T/fnm_multishells/20546_1681215510586/bin/npm
npmPackages:
jest: ^29.3.1 => 29.3.1
Having the same issue. Jest explicitly calls out not recognizing satisfies
from typescript. Removing satisfies runs the test correctly.
} satisfies Color);
^^^^^^^^^
SyntaxError: Unexpected identifier
Hitting this same issue 😄 Need any help moving this along?
Having the same issue. Any updates on this? It mentions in the changelog that v29.1.0 supports Typescript 5.x
same issue with jest" 29.5.0, any updates?
Same here. Jest 29.5.0, typescript 4.9.5
Same here. Bummer that this has been an issue for 5 months.
Typescript: 5.0.4 ts-jest: 29.1.1 jest: 29.6.2
It's quite impressive how it can't go along with TypeScript changes.
Any ideas how to handle that?
My code is more safe with satisfies
than with unit tests, but still need to make coverage target :skull:
Same here it's been around one year now with no update from the team. satisfies
is widely used by now, and still no support from ts-jest
I don't know what the difficulties are in integrating the management of the satisfies operator into ts-jest
. But it's a bit complicated not to be able to use a widely used typescript operator because the tests don't support it…
Could we know why this is not integrated yet? What technical difficulties are you encountering?
I don't see the Reference Error
anymore. Does anyone have reproduce repo for this?
@ahnpnl ya, I have no idea what changed when but I am able to use satisfies now.