Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Instantiation is Excessively Deep Regression In #56004 #59667

Open
LukeAbby opened this issue Aug 17, 2024 · 0 comments
Open

Type Instantiation is Excessively Deep Regression In #56004 #59667

LukeAbby opened this issue Aug 17, 2024 · 0 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@LukeAbby
Copy link

πŸ”Ž Search Terms

Type Instantiation is Excessively Deep, #56004

πŸ•— Version & Regression Information

This changed in commit 38ef79e

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAQg9gExAYQBYQMYGsDOAJCAJwEtgBDAcwgB4B5APigF4paoIAPYCAOwRygAFADZkMEMgCNhEWpIBWmYFAD8rKAC4oPCADciAbgBQoSFGRweOYITLEewNJlwES5KnXZde-IaPFSMnKKGMCMLGQ8IMZGAPSxUAByZAC20CkArtZe3HxQOHBpwKj2FFDEAHQQFVAABgDiEI6WAGbEFBmEEAjUyWnhUBVDtVAYhWDEMgKSGcrFxAIIcBA4PADkwBUm4NCNzTxtHV09fdCcub6RIAMWVjZ2Dk7Y+ESklDRGULCIKOjPrm8PJ8vlB4uZUJEKKUoPMBMA4HVTjkfAIAEQAQRSkmIvGAABl2qhgKjVFBMdjcQSKETNFAACpwLC8EZtDgrGHoUbjSZkYDESxbEFQACSd0i4jpO2owKFSPOKKgGKxOIcVKJJLUpggcBaZOVlMJyi0Wp19MZvBlUHowOt9BiYPRMJ2UDAZFsRSI5QEXQAjhliMcoC04IQOQsuSkJqI+ZYg3ZhJ1qiLlBhIlBJNAst0oJEEPk+cJhHHJjCEWNI5NoDNlMRdaQ1t6ICk4Po87iAxBhCByinuVMtghMKIuqNRDgBCIxBJpLIFEpqABVHhZvMRKKMADewLBDOLRfhEaj6SyvYcDxzPCgcDAMZ4ZCLYEI16IoA5vKgXRaRDhCNqsNqgo5ioxolDgMRfDuoEuk+kCEK+nALMAP5QAgtZfl0DjELy0AtE+KQctAWp1BuAC+IzVj2XrrMoYjABk95dtomArDgbrdgeqZZgRh48ree6JoBADEPBwMAACikagMahAZBAxgkUYcQJLuOCoHAADuYYCOWUa8vyl4tPGibcRgY7aXAGTCHmwikEQDHdhmUDyCedSmWQ456hSqqGlApEAcmUAQshCHZMUFnUgOQ5utAbkeeSKr4j58p8BO-jTkEc6hL5wLCaJEk3iA0myfJimDm5I6xQIDJMpeyW+JOAQzsESjZRBCQALIuZ+noHpEonoKGj7PnBIA1H+oEjPeljQAs1HsCJGQRcCkggQsADaqIYKiAC64GggktA8IxIVIaW6bQN1hCBvCNR0pgqA8MQqaFt2IAWVyll5l0zb6FpF55sU0Copw4jjsQ+iMYOEBgCSRBPqGSwrHNFAImQ6lkKN24JHgGl6D1EIpmQWYCH1gOhjpvH6ewV0hoBGBaMuWKGEYJFAA

πŸ’» Code

type BodyChecksHeritage<O> = O extends PlaceableObject ? O : never;
type ConstraintChecksHeritage<O extends PlaceableObject> = any;

// Name must extend something i.e. `GetConfigured<Name> = ...` compiles but this doesn't.
type GetConfigured<Name extends any> = ConstraintChecksHeritage<
  BodyChecksHeritage<
    // Changing this to `Name extends "AmbientLight" ? AmbientLight : Token` fixes the compilation.
    InstanceType<
      Name extends "AmbientLight" ? typeof AmbientLight : typeof Token
    >
  >
>;

// A type parameter is required for this compilation failure. It can be used and still fail to compile but if it's removed entirely it compiles.
declare class PlaceableObject<Unused = any> {
  // To fail to compile must contain an optional property that refers to `this`.
  a?: this;

  // This property exists to differentiate from the type `{}` but it isn't actually necessary to cause the compilation failure.
  #notEmpty: true;
}

// To show this compilation failure the class could literally be just `class AmbientLight {}`. It has to exist though.
declare class AmbientLight extends PlaceableObject {
  #notEmpty: true;
}

declare class Token extends PlaceableObject {
  // Must refer to another property. `this` alone isn't enough.
  b: this["c"];

  // Only exists to be referred to. Technically you could remove this and the "excessively deep" error doesn't go away.
  // However that causes another compilation error.
  c: number;
}

πŸ™ Actual behavior

Gets the error "Type instantiation is excessively deep and possibly infinite."

πŸ™‚ Expected behavior

No error.

Additional information about the issue

I've seen somewhat similar issues reported about this PR but none of them seemed to match my issue. However some were closed without reproduction and maybe I'm having the same problem as type-fest is?

I've reduced the code down from a large project into this which is why it seems utterly contrived. A few of the odd requirements seem to be explainable:

But that leaves some things I can't personally explain such as:

  • Why is a?: this causing issues but a: this | undefined or others don't necessarily?
  • Why does PlaceableObject have to be generic?
  • etc.

I've noted more oddities inline with the code.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants