Skip to content

Commit

Permalink
型推論の説明修正
Browse files Browse the repository at this point in the history
  • Loading branch information
mikinovation committed Mar 30, 2024
1 parent 96a1515 commit 37cfca4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/reference/type-reuse/utility-types/no-infer.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ getIndexFromArray(fruits, "apple");
getIndexFromArray(fruits, "peach");
```

上の例だと`getIndexFromArray`の第二引数には配列に含まれていない`peach`という文字列を指定することができてしまいます。しかし配列に含まれている要素のみを許容したいです。そこで`NoInfer`を利用することにより`T`の型推論を防ぐことができます。
このとき`T``"grape" | "apple" | "banana" | "peach"`と推論されてしまいます。しかし第二引数には配列に含まれている要素のみを許容したいです。そこで`NoInfer`を利用することにより`T`の型推論を防ぐことができます。

```ts twoslash
function getIndexFromArray<T extends string>(
Expand Down

0 comments on commit 37cfca4

Please sign in to comment.