Skip to content

Irregular Class Return Values not being Reflected Correctly with Types in TS #43272

Closed
@NightshadeX9X

Description

@NightshadeX9X

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.

Activity

RyanCavanaugh

RyanCavanaugh commented on Mar 16, 2021

@RyanCavanaugh
Member

Duplicate #27594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @RyanCavanaugh@NightshadeX9X

        Issue actions

          Irregular Class Return Values not being Reflected Correctly with Types in TS Β· Issue #43272 Β· microsoft/TypeScript