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

tsc declaration-emits any type for self-referring class expressions #56479

Closed
h-joo opened this issue Nov 21, 2023 · 4 comments
Closed

tsc declaration-emits any type for self-referring class expressions #56479

h-joo opened this issue Nov 21, 2023 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@h-joo
Copy link
Contributor

h-joo commented Nov 21, 2023

πŸ”Ž Search Terms

declaration, any, class expressions

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 'any'

⏯ Playground Link

https://www.typescriptlang.org/play?jsx=0&module=1&ts=5.3.1-rc#code/MYewdgzgLgBAhjAvDYAbOEIwIIwN4BQMxMATgKZwAm4qAnvAFw5IxjkDuOAFAJQDcBAL5A

πŸ’» Code

const a = class A {
    readonly a: A = new A();
}

πŸ™ Actual behavior

TSC emits the following declaration (I think due to literal types does not have a recursive representation):

declare const a: {
    new (): {
        readonly a: any;
    };
};

πŸ™‚ Expected behavior

Either or both :

  • Whenver TypeScript is trying to print any type during declaration emit it should rather be an error.
  • This should also be solved when TS is able to express the type of the class expression properly equivalent to class types. So the actual "Expected behavior" should be decided by the TypeScript team on what the correct solution for these kind of pattern is, but either a solution is to provide a representation for class types, or allowing initializers in declaration emit for class expressions would both solve the issue.

Additional information about the issue

This was noticed during the development of --IsolatedDeclarations, and we decided to not support declaration emit for class expressions as it was complicated an hacky to replicate what the current TSC is doing.

Related issue in terms of discrepancy between class declaration emit and class expression emit : #56145

@fatcerberus
Copy link

Kinda-sorta a duplicate of #55832

@fatcerberus
Copy link

This should also be solved when TS is able to express the type of the class expression properly equivalent to class types.

That'd be #41581, though I don't think this case in particular would ever be representable since the correct emit would nest forever.

@jakebailey
Copy link
Member

We should really create some sort of mega-issue for the things noted by isolated declarations; deduping them on very old issues is kinda unfortunate without some sort of tracking to indicate that these are very real things we were hoping to fix for isolated declarations and beyond.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants