Circular constraint reference in typings/utils.d.ts
See original GitHub issueDescribe the bug We are migrating to Envelop and ran into a very odd error when trying to boot up.
node_modules/typescript/lib/lib.es5.d.ts:1553:11 - error TS2313: Type parameter 'P' has a circular constraint.
just for reference, this line is Pick
/**
* From T, pick a set of properties whose keys are in the union K
*/
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
This was all the output and we began bashing our own code to try and find the error, finally after running tsc --build --verbose
we got it to print the origin inside Envelop
node_modules/typescript/lib/lib.es5.d.ts:1553:11 - error TS2313: Type parameter 'P' has a circular constraint.
1553 [P in K]: T[P];
~
node_modules/@envelop/types/utils.d.ts:13:93
13 export declare type Spread<A extends readonly [...any]> = A extends [infer L, ...infer R] ? SpreadTwo<L, Spread<R>> : {};
~~~~~~~~~~~~~~~~~~~~~~~
Circularity originates in type at this location.
for reference, it’s this line with references its own type
Spread<A extends readonly [...any]> = A extends [infer L, ...infer R] ? SpreadTwo<L, Spread<R>> : {};
I’ve tried updating the line to
Spread<A extends readonly [...any]> = A extends [infer L, ...infer R] ? SpreadTwo<L,R> : {};
Which solved the issue on our codebase. Doing the same in envelop repo produces green tests and builds.
I can make a PR with this change but wanted to check first if it should be moved into its own type or what the purpose of it is.
To Reproduce To be fair, I don’t know how to reproduce it in Envelop repository, I’ve tried with --build --verbose and it does not give the same output. My colleague and I get the same error on our different machines with our codebase.
Expected behavior No typings errors
Environment:
- OS:
"@envelop/core"
: “^1.4.0”,typescript
tested on4.3.4
and4.5.4
tsc-watch
: “^4.2.8” for development mode- NodeJS: 12.18.3, 14.17.3
Additional context We use a monorepo, each service have its own packages/typings
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:10 (2 by maintainers)
@Cuel I think this comes for a specific TypeScript setup you have in your project? (and I guess that’s why
skipLibCheck: true
solves that). The reason it’s using a circular definition is that we wanted to be able to recursively merge the context type when more than 2 types are used, so we “iterate” the array of types[infer L, ...infer R]
and merge the with the previous type.I wonder why it’s not emitting this error in our codebase - do you have a specific tsconfig configuration file that checks that? 🤔
@kamilkisiela thoughts?
For now we can get around it with
skipLibCheck: true
in tsconfig.json