Microsoft/TypeScript

Accessors are always reduced to properties in object literal declarations

Open

#53,775 建立於 2023年4月14日

在 GitHub 查看
 (0 留言) (1 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

Bug Report

Currently, accessors in object literals are condensed in plain properties - this an issue when get/set use different types. The workaround is to explicitly specify the type (see playground). Ideally, accessor should be preserved in declaration files, when possible.

🔎 Search Terms

accessors, object literal

🕗 Version & Regression Information

/

⏯ Playground Link

Playground link with relevant code

💻 Code

export const Foo = {
    get bar(): number { /* ... */ },
    set bar(value: number | string) { /* ... */ }
};

🙁 Actual behavior

export declare const Foo: {
    bar: number;
};

🙂 Expected behavior

export declare const Foo: {
    get bar(): number;
    set bar(value: number | string);
};

貢獻者指南