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

RangeError: Maximum call stack size exceeded Regression in #52392 #60927

Open
LukeAbby opened this issue Jan 7, 2025 · 0 comments
Open

RangeError: Maximum call stack size exceeded Regression in #52392 #60927

LukeAbby opened this issue Jan 7, 2025 · 0 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@LukeAbby
Copy link

LukeAbby commented Jan 7, 2025

🔎 Search Terms

RangeError: Maximum call stack size exceeded, #52392

🕗 Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAbwL4G4BQaAmwDGAbAQymDgICMBnGKAnefAiiuAFQE8xgARAmAgWQjY8AHgAKRYADsYAPkRo4cMJJkAuOBOIz0i5cRXEuwKAEsAbsEw8+ACj1KYAC1MUNz13FAxpmZgmVVGA1TKQAzEzgAfTgkOAB+OClgSyg4DWTUvQBKDXMIU0x0JAxsBmI4BiY4ACFGYABJHwBbLxAfKT84LggcAFdm6RgRAik2eQQ9QyGNOopGloA6LSHirFxCCqkCQYoVHBI5heBWyccOEhWZOABeOBgLiDC4AEE6aDEWACUAJmA19blEgAczwEDIBDwCiU212+xIYQgfU6UDY0KUbUgsDgpmaWPgUQAqlI+vNMLdavUmid0EoSiVAZsSFVmNTWt5fMwev1BtdkKUNpJKoRqgAxCB4bBQT6-EhnOAgdyPZ5vGAfb5-AFlJnCxjMVXq2XothKzhPODiyUmGWavQALw07E4NgEQmAogeZuebNkAM9JGMwDAWhgpkhIhYbQ6XXBACtcHIKfKANoAaRxUjgAGtgGxzSwALrxDRRQPBoih8MsNMF31oVBof3RMshsOiFjyO6RjmdZhxhMJbrAIOtqvyR26bVClndXoDIYAZScw5gADUfiJufOZAAaOAAYQg4VMwL6NFDR6jnLg-boFNG43ROCPVCgfXeUHsGJvYAvUjcQ4jhWbYiIex6nuephHvIABk6Lfpgc68sEs48qsDixDkWqChUz7-vAiJWlAprAOalpSja-xoMkADuqHbjAS4ruutgBIhaHqHAhFSrE2ToEAA

💻 Code

export {};

declare abstract class TypeDataModel<Parent> {
  parent: Parent;

  prepareDerivedData(
    this: this extends { parent: infer _ } ? never : never
  ): void;
}

declare class BaseItem extends Document<any> {
  parent: BaseItem.Parent;
}
declare namespace BaseItem {
  type Parent = typeof ActorPTR2e;
}

declare global {
  namespace foundry {
    export import _Unused = BaseItem;
  }
}

declare class Item extends Document {}

declare class FolderPTR2e {
  x: typeof ActorPTR2e;
}

declare class ActorPTR2e {
  y: typeof FolderPTR2e;
  z: TypeDataModel<typeof Item>;
}

type DeepPartial<T extends object> = {
  [K in keyof T]?: _DeepPartial<T[K]>;
};
type _DeepPartial<T> = T extends object ? DeepPartial<T> : T;

declare class DocumentSheetV2<Document, Configuration extends object = any> {
  constructor(
    options: DeepPartial<Configuration> & {
      document: Document;
    }
  );
}

declare const folder: typeof FolderPTR2e;
new DocumentSheetV2({ document: folder });

🙁 Actual behavior

The compiler crashes with RangeError: Maximum call stack size exceeded.

RangeError: Maximum call stack size exceeded
    at structuredTypeRelatedToWorker (node_modules/typescript/lib/_tsc.js:64885:43)
    at structuredTypeRelatedTo (node_modules/typescript/lib/_tsc.js:64817:21)
    at recursiveTypeRelatedTo (node_modules/typescript/lib/_tsc.js:64768:19)
    at isRelatedTo (node_modules/typescript/lib/_tsc.js:64186:122)
    at isPropertySymbolTypeRelated (node_modules/typescript/lib/_tsc.js:65563:14)
    at propertyRelatedTo (node_modules/typescript/lib/_tsc.js:65603:23)
    at propertiesRelatedTo (node_modules/typescript/lib/_tsc.js:65814:29)
    at structuredTypeRelatedToWorker (node_modules/typescript/lib/_tsc.js:65361:21)
    at structuredTypeRelatedTo (node_modules/typescript/lib/_tsc.js:64817:21)
    at recursiveTypeRelatedTo (node_modules/typescript/lib/_tsc.js:64768:19)

(this is on 5.8.0-dev.20250106 but the same error appears on 5.7.2 and several other versions I tested as well as all the ones I bisected)

🙂 Expected behavior

Regular errors. This file has a few but in my original repo there were less, possibly none?

The editor doesn't crash and reports these errors:

Type instantiation is excessively deep and possibly infinite.
Expression produces a union type that is too complex to represent.

On DocumentSheetV2. I find the second one odd because there's not a single union in the program.

There's also the error:

No base constructor has the specified number of type arguments.

On Document<any>, because Document doesn't take type arguments. In my original repo I wasn't passing a generic to a class without one but this was the easiest way to reliably reproduce it. I can get it to work without the <any> but it was simply less reliable while I was reducing so I left it in.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 8, 2025
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.8.0 milestone Jan 8, 2025
LukeAbby added a commit to League-of-Foundry-Developers/foundry-vtt-types that referenced this issue Jan 9, 2025
LukeAbby added a commit to League-of-Foundry-Developers/foundry-vtt-types that referenced this issue Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants