Closed
Description
Bug Report
Irregular Class Return Values not being Reflected Correctly with Types in TS
β― Playground Link
Playground link with relevant code
π» Code
class X {
constructor() {
return { b: 42 };
}
}
// EXPECTED: The value X should be of type `new () => { b: number }`
// REALITY: The value X is of type `new () => {}`
const x = new X();
// EXPECTED: The value x should be of type X, which should equate to type `{ b: number }`
// REALITY: The value x is of type X, which equates to `{}`
x.b // UNEXPECTED ERROR
π Actual behavior
Classes with no properties/methods defined outside the constructor have a return type of {}
π Expected behavior
I expected classes to be typed correctly, and reflect the type that they actually return.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
RyanCavanaugh commentedon Mar 16, 2021
Duplicate #27594