How do I define a type for
string|string[]|string[][]|string[][][] // ad infinitum
in typescript?
edit: the solution would be:
type Rec = string | string[] | Rec[]
but that is not allowed.
Here is my usecase:
interface RecursiveArray<T> {
[index: number]: (RecursiveArray<T> | T);
}
type Recursive<T> = T|RecursiveArray<T>
function stringValue (value: Recursive<string|boolean>): Recursive<string> {
if (typeof value === 'boolean') {
return value ? 'true' : 'false';
}
if (Array.isArray (value)) {
return (value).map (stringValue);
}
return stringValue(value);
}
any, but that's not well typed. Have you tried to type it as anArray<string>?