-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Question: is there a more elegant way to representing type Line = string | Line[]
?
#3988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think we have a way to represent an infinitely-expanding type alias like this. |
A shorter and sillier way of writing this type to depth 10 let x = ['', ['', ['', ['', ['', ['', ['', ['', ['', ['']]]]]]]]]];
type Line = string|typeof x; |
+1 i like it |
I think #3496 covers your initial request. |
|
@jeffreymorlan 🏆 👍! |
whose name shall it put on the check? |
Looks like the original issue has been answered. please reactivate if you are running into other issues. |
There's an interesting limitation to the suggestion in #3988 (comment). Given type ItemOrArray<T> = T | ItemArray<T>;
interface ItemArray<T> extends Array<ItemOrArray<T>> { } the following const items: Array<ItemOrArray<number>> = [1, [2, [3, ["4"]]]]; will report an error
but const items: Array<ItemOrArray<number>> = [1, [2, [3, [4, ["5"]]]]]; will not. Edit - this seems related to #13052. |
I wish I could define a type as follows
Looks like it's there is a fundamental limitation in the type system that doesn't allow doing so.
I ended up having my type defined like this:
but I don't like it because it only works that many times
Is there a more elegant and typesafe way of getting a type like this that works beyond 27 nested levels?
The text was updated successfully, but these errors were encountered: