3
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 3 years have passed since last update.

TypeScript: Append<[1,2], 3> ─ タプル型の最後に要素を追加するユーティリティ型

Posted at

TypeScriptでタプル型の最後に要素を追加した型を導出するユーティリティタイプです。

Append<T, U>

type Append<T extends unknown[], U> = [...T, U]

可変長タプル型が導入されたTypeScript 4.0以降で使えます。

使用例

const t1: Append<[], 1> = [1]
const t2: Append<[1], 2> = [1, 2]
const t3: Append<[1, 2], 3> = [1, 2, 3]
const t4: Append<[boolean, null, undefined], number> = [false, null, undefined, 0]

試す

このユーティリティタイプを試したい方は、TypeScript Playgroundをご覧ください。

3
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
3
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?