question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular constraint reference in typings/utils.d.ts

See original GitHub issue

Describe 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 on 4.3.4 and 4.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:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dotansimhacommented, Dec 20, 2021

@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?

1reaction
Cuelcommented, Dec 20, 2021

For now we can get around it with skipLibCheck: true in tsconfig.json

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular constraint reference in typings/utils.d.ts #1120 - GitHub
Describe the bug We are migrating to Envelop and ran into a very odd error when trying to boot up.
Read more >
How to create a circularly referenced type in TypeScript?
The creator of TypeScript explains how to create recursive types here. The workaround for the circular reference is to use extends Array ....
Read more >
Is it acceptable to have circular foreign key references\How to ...
Accounts ( AccountID INT NOT NULL CONSTRAINT PK_Accounts PRIMARY KEY CLUSTERED ... No, it's not acceptable to have circular foreign key references.
Read more >
Circular dependency / referencing in typescript - Cocos Forums
I have 3 classes (A, B, C) A.ts import B from "./B"; const {ccclass, property} = cc._decorator; @ccclass export default class A extends...
Read more >
Circular constraint reference in typings/utils.d.ts - Dotansimha/Envelop
This issue has been created since 2021-12-17. Describe the bug. We are migrating to Envelop and ran into a very odd error when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found