この記事の内容は TypeScript のv4.1.3で、compilerOptions.noUncheckedIndexedAccessを有効にした状態で動作確認している。 参考: zenn.dev 恒等関数(Identity Function)とは、渡されたものを返す関数。 function identity<T>(arg: T) { return arg; } const x = identity(1); // const x: 1 const y = identity(() => 1); // const y: () => 1 引数をそのまま返しているため当然だが、値は変わらない。 このままだと何の意味もないが、extendsキーワードを使って型に制約を与えることができる。 例えば以下のidentityには、ReturnNumberかそのサブタイプしか渡せない。 type Retu