Microsoft/TypeScript

Accessors are always reduced to properties in object literal declarations

Open

#53 775 ouverte le 14 avr. 2023

Voir sur GitHub
 (0 commentaires) (1 réaction) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: Declaration EmitHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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);
};

Guide contributeur