TS2706
error TS2706: Required type parameters may not follow optional type parameters.
Broken Code ❌
1 |
|
Fixed Code ✔️
The generic type Key
is defined with a default value of string
which makes this type parameter not optional. However, the Value
type parameter is optional and optional parameters are not allowed to follow required parameters.
To solve the situation, we have can switch the position of the two parameters which would impact how we use the code:
1 |
|
Alternatively, we can also set a default type for Value
:
1 |
|