Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

More examples of `infer`

オープン 初心者向け
#2,998 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
typescript
領域
documentation

調査の方向性

Conditional Types のドキュメントセクションから始め、既存の infer の例を確認してください。配列の先頭要素の削除、template literal のパース、単一文字の推論、再帰を扱う例を追加し、その後、例が正しくレンダリングされ、記載された結果の型が正確であることを確認してください。

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

説明

Documentation is lacking in examples of how to use infer in the Conditional Types section.

For example, one can use infer to unshift an array literal:

type Unshift<T extends any[]> = T extends [infer Head, ...infer Tail] ? Head : never;
type A = Unshift<['a','b','c']>

type A is literal 'a'.

Another useful example would be to demonstrate infer within a template to parse a string type:

type TSVersion = "4.1.2"
type ExtractSemver<Semver extends string> =
    Semver extends `${infer Major}.${infer Minor}.${infer Patch}` ?
    { major: Major, minor: Minor, patch: Patch } : never
type TS = ExtractSemver<TSVersion>

type TS is literal { major: "4", minor: "1", patch : "2"}

Also useful would be to demonstrate the default of infer will be a single char, and to demonstrate recursion:

type NotEmptyString<S extends string> = S extends "" ? never : S;
type Reverse<S extends string> = 
	S extends "" ? S : 
	S extends `${infer B}${infer E}` ? `${Reverse<E>}${B}` : never;
type WorkItAndReverseIt = Reverse<"Foobar">;

type WorkItAndReverseIt is literal rabooF.

主要言語
TypeScript
スター
2.6k
フォーク
1.5k
平均マージ
2日 21時間
マージ済み PR(30日)
7

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

microsoft/TypeScript-Website のほかの issue

microsoft/TypeScript-Website の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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