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

Surprising circularity when parameter within base type expression refers to the class itself #58391

Closed
Andarist opened this issue May 1, 2024 · 0 comments Β· Fixed by #58392
Closed
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@Andarist
Copy link
Contributor

Andarist commented May 1, 2024

πŸ”Ž Search Terms

circularity base expression class single call signature callback parameters

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240501#code/JYOwLgpgTgZghgYwgAgApQmMBPAPAFQHsA+ZAbwChlkAKOALmSIEpGBnMKUAcwG4KAvhQqhIsRCgDKCABYQAtnFwBBUpWoY4AE0IgANtmQAHDFmwB+Rukw4VxfkJHho8JMgDCeuGzZ3yVZBAIAHdaVmRlB2EtCAQvDGQEXQ4PLx9GXEkIPRhiGgDgGPBgGGBodk4eABoKZmQAXlJcADEyvS02PIDS7I7GVt62Guo4EBBCMDgwYGTLZGk5RUzs3Jq6xtTvXwB5AFcwI33mqEJ5FraO4nthHCMUfGw7gj2D-dJ6-2oAfXwXw7BGL99v8HPwKLcUH8jiczvgBu1Og1PsgANoAaWQoGQAGsINhCDAmPCOgBdRgAIh+ULA5OQEAAHpAQB0cXiCUSLmx0SSAtRzBzBtyUZSga8aTzqNRGEEAG7QUHRWLxFAwXYgBDTXTIDhcEDcGjhB5PHU8a4UBlGQhQMCJNJsCJ0xkQZn2zxbOw0cnKcnMfLUMjIBjayp65ACYbI6gmGzYRh0dakABSkm2ADkAHQmvUlbDxiPh2rkARAA

πŸ’» Code

interface Pretty<To> {
  (a: To): string;
}

interface Schema<A> {
  readonly pretty?: Pretty<A>;
}

interface Class<A> {
  new (): A;
}

declare const Class: <Self>(
  identifier: string,
) => <Fields>(
  fields: Fields,
  annotations?: Schema<Self>,
) => Class<OutputFrom<Fields>>;

type Type<TOutput> = {
  _TOutput: TOutput;
};

type OutputFrom<TFields> = {
  [K in keyof TFields]: "_TOutput" extends keyof TFields[K]
    ? TFields[K]["_TOutput"]
    : never;
};

declare function string(): Type<string>;

export class A extends Class<A>("A")(
  { a: string },
  {
    pretty: (a) => JSON.stringify(a),
  },
) {}

πŸ™ Actual behavior

Type 'A' recursively references itself as a base type.(2310)
'A' is referenced directly or indirectly in its own base expression.(2506)

πŸ™‚ Expected behavior

No error. Correct declarations can be emitted for this without any problems

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels May 1, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants