You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
why is type T = (x: T) => void valid whereas T = T isnt? #12525
Note that object type literals, function type literals, and constructor type literals do not depend on types referenced within them and are therefore permitted to circularly reference themselves through type aliases.
The restriction that a type alias can't be referenced by itself at the top level has been the behavior since we implemented type aliases; however, you might recall that a while back, we started allowing type aliases to be referenced from within an object type.
If we desugar T's declaration to use object type, we can that under the current rules, it's allowed.
typeT={(value: T)=>void};
Overall this is actually pretty reasonable - even Haskell can't express something like this:
typeWat=Wat
<interactive>:1:1: error:
Cycle in type synonym declarations:
<interactive>:1:1-14: type Wat = Wat
However, it has no problem provided that the type can be expanded, or "unrolled" one level at a time. In other words, as long as you have some sort of box-y thing containing the type:
Activity
HerringtonDarkholme commentedon Nov 28, 2016
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#310-type-aliases
DanielRosenwasser commentedon Nov 28, 2016
The restriction that a type alias can't be referenced by itself at the top level has been the behavior since we implemented type aliases; however, you might recall that a while back, we started allowing type aliases to be referenced from within an object type.
If we desugar
T's declaration to use object type, we can that under the current rules, it's allowed.Overall this is actually pretty reasonable - even Haskell can't express something like this:
However, it has no problem provided that the type can be expanded, or "unrolled" one level at a time. In other words, as long as you have some sort of box-y thing containing the type:
the type system will be okay.
zpdDG4gta8XKpMCd commentedon Nov 28, 2016
is there any chance for recursive types in unions?
mhegazy commentedon Nov 28, 2016
tracked by #6230