2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TypeScriptで自己参照

Posted at

自己参照っていう言い方が正しいかわからないですが。。

たとえばこういうやつ :point_down:
冗長なのでもっと楽したい。けどわざわざ型を追加したくもない。

interface Player {
  status: "playing" | "stopped";
  prevStatus: "playing" | "stopped";
}

環境

TypeScript 3.6.2

こうやる

thisを使います。

interface Player {
  status: "playing" | "stopped";
  prevStatus: this["status"];
}

以上です :hugging:

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?