We can check if an element exist in an array using `extends`
We can check if an element exist in an array using `extends`
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.
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.
To avoid type narrowing for string utilities, we can recast it using string utility types.
To avoid type narrowing for string utilities, we can recast it using string utility types.
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 😂)
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 get the return type, we can `infer` it.
To get the return type, we can `infer` it.
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.
1. Array is an object, so you can iterate it as you would iterate mapped types, which doesn't have stack overflow issues
2. The elements are a tuple, so you can quickly access the members by their indexes.
3. You can extract the numerical value by infering the numeric string.
1. Array is an object, so you can iterate it as you would iterate mapped types, which doesn't have stack overflow issues
2. The elements are a tuple, so you can quickly access the members by their indexes.
3. You can extract the numerical value by infering the numeric string.
The key extraction is a bit hacky though!
The key extraction is a bit hacky though!
No, you don't need to export the types.
No, you don't need to export the types.
You can actually erase the type here.
You can actually erase the type here.