Closed as not planned
Description
π 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
π» 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