Closed
Description
Suggestion
π Search Terms
class expression declaration type
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest ofTypeScript's Design Goals.
β Suggestion
When a class is created by a static method, there doesn't seem to be a way to directly use it as a class type.
π Motivating Example
Implementation:
class BaseClass {
static cloneClass() {
return class extends BaseClass { }
}
}
How I would expect the declaration to look, with the type error present now:
declare class BaseClass {
static cloneClass(): class extends BaseClass {};
// ~~~~~
// Cannot find name 'class'.
}
The declaration actually created:
declare class BaseClass {
static cloneClass(): {
new (): {};
cloneClass(): any;
};
}
π» Use Cases
Similar to #45013: it's difficult to represent class "factories" like this one in type declarations.