Repository navigation
Recursive type definitions regression in 3.4.0 #30841
Description
Activity
Recursive type aliases are, unfortunately, not supported - see #3496, #6230, and #24897 (comment).
Recursive type aliases are, unfortunately, not supported - see #3496, #6230, and #24897 (comment).
However, the code above did work before 3.4.0, and the infered type is correct.
- addedDuplicateAn existing issue was already createdAn existing issue was already created
on Apr 10, 2019 RyanCavanaugh commented
on Apr 10, 2019 MemberMore actionsThis didn't actually work in the past, you were just getting a silent
anyin most cases. Conditional types are now simplified more often and TS may detect a circularity earlier than before.This didn't actually work in the past, you were just getting a silent
anyin most cases.Nope. The following derived
Typesworks as expected before 3.4.0 (test in 3.3.4), and no silentany.const makeAction = <T extends string, P extends object, Args extends any[]>( type: T, fn: (...args: Args) => P, ) => { const action = (...args: Args) => { const ret = fn(...args) as P & { type: T } ret.type = type return ret } action.type = type return action } const actions = { a: makeAction('a', () => ({})), b: makeAction('b', (a: number, b: string) => ({ a, b })), } type Types = ActionType<typeof actions> const fn = (data: Types) => data fn(actions.a()) // work as expected fn(actions.b(1, 'a')) // work as expected fn(actions.c()) // ts error due to Property 'c' does not exist fn({ type: 'c' }) // ts error due to Type '"c"' is not assignable to type '"a" | "b"'.ts(2322)
The
Typesis infered as expected (infered info from VSCode).type Types = { type: "a"; } | ({ a: number; b: string; } & { type: "b"; })
Conditional types are now simplified more often and TS may detect a circularity earlier than before.
It means that ts >= 3.4.0 will make the above code illegal intentionally (because of detecting a circularity earlier than before)?
typescript-bot commented
on Apr 13, 2019 ContributorMore actionsThis issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
Recursive
Conditional
Code
Expected behavior:
No errors. It's worth noting that it works in 3.3.4, with the correct derived type.
Actual behavior:
Running
tsccommand line, it reports the following errors:Playground Link:
Related Issues: