Suppose we have a scenario where an interface/type is defined as follows:
interface ITest {
abc: string[]
}
and then it is assigned to an object like this:
const obj: ITest = {
abc: ["x", "y", "z"]
}
We then attempt to create a type based on the values of the abc property...
type ABCVal = (typeof obj.abc)[number]
As a result, ABCVal
is simply string
Is there a way for ABCVal
to be equal to "x" | "y" | "z"
while still enforcing that the abc
array can only contain strings?