Skip to content

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

Closed as not planned
@h-joo

Description

@h-joo

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions