Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve set-only accessors in declaration emit #58119

Open
DanielRosenwasser opened this issue Apr 8, 2024 · 0 comments
Open

Preserve set-only accessors in declaration emit #58119

DanielRosenwasser opened this issue Apr 8, 2024 · 0 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 8, 2024

Playground Link

Related to #58112 (comment)

export let same = {
    set x(value: string) {
    },
    get x(): string {
        throw new Error("Not implemented.")
    },
};

export let divergent = {
    set x(value: string) {
    },
    get x(): number {
        throw new Error("Not implemented.")
    },
};

export let readonly = {
    get x(): string {
        throw new Error("Not implemented.")
    },
};

export let writeonly = {
    set x(value: string) {
    },
};

Current

Notice that in the declaration of writeonly, we don't preserve the accessor at all.

export declare let same: {
    x: string;
};
export declare let divergent: {
    get x(): number;
    set x(value: string);
};
export declare let readonly: {
    readonly x: string;
};
export declare let writeonly: {
    x: string;
};

Expected

If we had a writeonly modifier, I'd argue we could just use that as a parallel to the readonly declaration; however, we do support accessors in declaration emit, and we could emit that in the case of a write-only accessor.

It is technically a breaking change though for consumers of older TypeScript versions, and the only way to opt out would be to declare a no-op get accessor.

export declare let same: {
    x: string;
};
export declare let divergent: {
    get x(): number;
    set x(value: string);
};
export declare let readonly: {
    readonly x: string;
};
export declare let writeonly: {
    set x(): string;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant