Skip to content
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

Recursive type alias in union type breaks in 3.8.3 #37344

Closed
stefanvonderkrone opened this issue Mar 11, 2020 · 2 comments · Fixed by #37481
Closed

Recursive type alias in union type breaks in 3.8.3 #37344

stefanvonderkrone opened this issue Mar 11, 2020 · 2 comments · Fixed by #37481
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@stefanvonderkrone
Copy link

stefanvonderkrone commented Mar 11, 2020

TypeScript Version: 3.8.3

Search Terms: recursive, recursion

Code

type Action<T, P> = P extends void ? { type : T } : { type: T, payload: P }

enum ActionType {
    Foo,
    Bar,
    Baz,
    Batch
}

type ReducerAction =
  | Action<ActionType.Bar, number>
  | Action<ActionType.Baz, boolean>
  | Action<ActionType.Foo, string>
  | Action<ActionType.Batch, ReducerAction[]>

Expected behavior: compiler does not complain recursive type alias, works fine in 3.7.5

Actual behavior: compiler complains recursive type alias, breaks in 3.8.3
Type arguments for 'Array' circularly reference themselves.

Playground Link:
http://www.typescriptlang.org/play/index.html#code/C4TwDgpgBAggxsAlgewHYB4AqAaKAFAPigF58oIAPYCVAEwGcoA3ZRWqAfigG8pRIoALiiYoAXyE8+4CMJxQwAQxAAbZItrC84gFA6aAVwC2sBClSYZPHVFtQAYsmTYbdgEKKATi7tQPALx93RWA4AAsdMT1+aAAlCFoDOAhPeCQ0ElcAH1N0jDTzS0gAOg9vKFRjACMUgmzc83QCtCKIUsVAqCqnFQhFVDrbHOb8sxaZYsdnKHpgT0RUAHNBqGGx0bzW9tCw3HjE5NT1gG0AXTqgA

Related Issues:
I'm not sure, if this might be related to #35017.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 11, 2020
@stefanvonderkrone
Copy link
Author

I must add that the recursive type definition of ReducerAction seems to break because of the conditionality of the Action type. If I remove the condition (type Action<T, P> = { type: T, payload: P }) then the type checking succeeds.

@weswigham
Copy link
Member

Aye. The conditional's check for simplifiability makes the circularly referential array type get resolved too soon. We should probably defer simplifying conditionals over deferred type references like we do generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
4 participants