-
Notifications
You must be signed in to change notification settings - Fork 12.8k
combinatorial explosion of recursive unions definitions. #18754
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'm not seeing this in the playground or the nightlies. |
@DanielRosenwasser I've seen that in VSCode, can you try in it? I have two concerns:
class CA { tag: 'a'; pa: CALL }
class CB { tag: 'b'; pb: CALL }
class CC { tag: 'c'; pc: CALL }
class CD { tag: 'd'; pc: CALL }
class CE { tag: 'e'; pc: CALL }
type CALL = CA | CB | CC | CD | CE |
Can you share some more context. like a bigger code sample? |
@mhegazy @DanielRosenwasser oh that's strange! I found out it happens when I do an import like this at the top of the file: import * as t from 'io-ts'
type A = { tag: 'a', pa: ALL}
type B = { tag: 'b', pb: ALL}
type C = { tag: 'c', pc: ALL}
type D = { tag: 'd', pd: ALL}
type E = { tag: 'e', pe: ALL}
type ALL = A | B | C | D | E Here's a repo exhibiting the issue, this one with latest TS 2.6.0-dev.20170926 ( happens on both that version and 2.5.2, I've not checked others ) : |
Actually, I'm even not requiring io-ts, I've updated the repo with a version that just tries to import an empty module. emptymodule.ts export { } test.ts import * as t from './emptymodule'
type ZA = { tag: 'a', pa: ALL }
type ZB = { tag: 'b', pb: ALL }
type ZC = { tag: 'c', pc: ALL }
type ZD = { tag: 'd', pc: ALL }
type ZE = { tag: 'e', pc: ALL }
type ALL = ZA | ZB | ZC | ZD | ZE |
Another variations happens with just export { }
type ZA = { tag: 'a', pa: ALL }
type ZB = { tag: 'b', pb: ALL }
type ZC = { tag: 'c', pc: ALL }
type ZD = { tag: 'd', pc: ALL }
type ZE = { tag: 'e', pc: ALL }
type ALL = ZA | ZB | ZC | ZD | ZE |
Also this one exhibit the error type ZA = { tag: 'a', pa: ALL }
type ZB = { tag: 'b', pb: ALL }
type ZC = { tag: 'c', pc: ALL }
type ZD = { tag: 'd', pc: ALL }
type ZE = { tag: 'e', pc: ALL }
type ALL = ZA | ZB | ZC | ZD | ZE
export { ALL } whereas this one not type ZA = { tag: 'a', pa: ALL }
type ZB = { tag: 'b', pb: ALL }
type ZC = { tag: 'c', pc: ALL }
type ZD = { tag: 'd', pc: ALL }
type ZE = { tag: 'e', pc: ALL }
export type ALL = ZA | ZB | ZC | ZD | ZE So there's a kind of 'workaround' so far.. |
@mhegazy @DanielRosenwasser enough information to emit a judgment if either this is a bug or a by design limitation? |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
This is definitely undesirable behavior, but can you give us more context on how you're running into this in the first place? Specifically, what is the motivating use-case? |
I am unable to get a repro for the issue described in this thread. @sledorze can you share a self-contained repro for the issue. |
@mhegazy here's a playground link that reproduce the issue: just hover over the ALL definition to see the types.. @DanielRosenwasser the use case is implementing a recursive algebra (a Query AST); the obvious work around is using interfaces instead of types but I found that pretty counter intuitive and unhandy that adding an export changes the type inference. |
I've been experiencing the same problem. I've converted all of minijs' AST types to interfaces, because IntelliSense was stopping to show up and after a considerable wait, tsserver was crashing. Here's a playground link demonstrating the problem when using |
I think that this has been the guidance we've had for users for a while. Still, I know this is unexpected. @ahejlsberg had an explanation of why we reuse type alias names in global contexts as opposed to within a module. |
There's a lot of difference going on now when switching from types to interfaces, I'm referring specifically to variance and type safety. |
Should be fixed in latest. |
TypeScript Version: 2.5.2
Code
Expected behavior:
When hovering on pa ... pe members, we see a few types, ideally just 'ALL'.
Actual behavior:
When hovering on pa ... pe members, we see an explosion of types.
The text was updated successfully, but these errors were encountered: