This particular line of code is causing an issue:
const oid: string | undefined = keyPath[0]
This is because the keyPath
array may contain elements of either number or string type.
Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
I also attempted the following:
const oid?: string = keyPath[0]
In Swift, I could utilize an as?
operator which attempts to cast a value to a specific type and returns an undefined if not possible. Is there an equivalent operator in Typescript that functions in a similar way?