jsii
jsii copied to clipboard
@types/jest v28 introduces circularly reference
Describe the bug
When using dependency "@types/jest": "28.1.3" a circular reference error is thrown:
:space_invader: build » compile | jsii --silence-warnings=reserved-word [2022-06-26T08:37:09.762] [ERROR] jsii/compiler - Compilation errors prevented the JSII assembly from being created node_modules/@sinclair/typebox/typebox.d.ts:237:21 - error TS2456: Type alias 'StaticIntersectReduce' circularly references itself. 237 export declare type StaticIntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? StaticIntersectReduce<I & A, B> : I;
using yarn why @sinclair/typebox
revealed that @sinclair/typebox is used by @types/jest .
Expected Behavior
no circular reference error thrown
Current Behavior
circular reference error thrown
Reproduction Steps
- Create new / update CDK construct library with projen (that should update the mentioned package to > 28
- run yarn build
Possible Solution
Fix version to 27.4.1 fixed the issue for me
Additional Information/Context
No response
SDK version used
1.61.0
Environment details (OS name and version, etc.)
MacOS
Looks like related to https://github.com/aws/jsii/issues/3609
Yeah - we are in this situation largely because we're still on TypeScript 3.9, and most of the ecosystem around us is gradually adopting TypeScript 4.3 to 4.5 minimum targets (for obvious reasons).
There is also https://github.com/aws/aws-cdk-rfcs/pull/373 where I propose to have jsii
and jsii-rosetta
follow TypeScript compiler versions, so we can easily follow the "current" TypeScript release train in the future...
In the meantime - the next release of jsii
will include #3623, which also introduces the ability to specify types
in the jsii.tsc
stanza in package.json
so you can manually pick what @types/*
packages are loaded in the global namespace, so you do not hit this problem when running jsii
(you would need to exclude tests from the jsii
compilation scope, and either use ts-jest
or compile them separately with a "recent" typescript
compiler -- that is definitely more work than pinning jest
to an older release 😭).
Would setting skipLibCheck to true prevent jsii from looking in node_modules to begin with?
Would setting skipLibCheck to true prevent jsii from looking in node_modules to begin with?
I'm not sure... it could have other consequences on the TypeChecker AST we obtain during parsing, so I'm reluctant to resort to this...