Day 13, this one is a bit difficult as we need to understand covariant and contravariant of TypeScript.
To enforce an invariant, we need to apply `out` to enforce contravariance and `in` to enfore covariance to the generic type.
To enforce an invariant, we need to apply `out` to enforce contravariance and `in` to enfore covariance to the generic type.
Comments
To get the return type, we can `infer` it.
Since I don't want to deal with some funny cases, I just implemented hacky helper functions to deal with it (don't do this 😂)
To avoid type narrowing for string utilities, we can recast it using string utility types.
The trick is to assert whether the generic is provided or not. If it's not provided, access the array element. Otherwise, return the generic as-is.