Skip to content

Should getters still infer the same type from setters over their return expressions? #43414

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
class C {
    #x = Promise.resolve("")

    set myValue(x: Promise<string> | string) {
        this.#x = Promise.resolve(x);
    }
    get myValue() {
        return this.#x;
    }
}

Should the get type of myValue be Promise<string> or just string | Promise<string>? Right now it is the latter; but technically, the former provides a more specific type.

Changing this technically would be a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions