Preserve `set`-only accessors in declaration emit

オープン
#58,119 コメント 0 件 リアクション 6 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
compilers

調査の方向性

リンクされた Playground から始め、same、divergent、readonly、writeonly の各アクセサーについて宣言出力を再現します。オブジェクトアクセサーに対する TypeScript の宣言出力パスを追跡し、既存のアクセサー関連のテストまたはベースラインと比較します。write-only アクセサーが、他に示されている出力を変更せずに、出力された宣言内で保持されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

In Discussion Suggestion

Playground Link

Related to https://github.com/microsoft/TypeScript/issues/58112#issuecomment-2043419380

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;
};
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。