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

TypeScript: Nested infer fails: Expected ">" but found "?" #2675

Closed
geirsagberg opened this issue Nov 14, 2022 · 1 comment
Closed

TypeScript: Nested infer fails: Expected ">" but found "?" #2675

geirsagberg opened this issue Nov 14, 2022 · 1 comment

Comments

@geirsagberg
Copy link

I have the following type, used as a return type for a function that recursively turns arrays into objects:

type Normalized<T> = T extends Array<infer A extends object ? infer A : never>
  ? Dictionary<Normalized<A>>
  : {
      [P in keyof T]: T[P] extends Array<infer A extends object ? infer A : never>
        ? Dictionary<Normalized<A>>
        : Normalized<T[P]>
    }

When I compile with esbuild, I get an error: ERROR: Expected ">" but found "?"

I have also made a test that fails: 2aac25c

Failure:

node scripts/plugin-tests.js
--- FAIL: TestTSTypes (0.01s)
    --- FAIL: TestTSTypes/type_Normalized<T>_=_T_extends_Array<infer_A_extends_object_?_infer_A_:_never>___?_Dictionary<Normalized<A>>___:_{_______[P_in_keyof_T]:_T[P]_extends_Array<infer_A_extends_object_?_infer_A_:_never>_________?_Dictionary<Normalized<A>>_________:_Normalized<T[P]>_____} (0.00s)
        ts_parser_test.go:183:
            +<stdin>: ERROR: Expected ">" but found "?"

FAIL
@evanw
Copy link
Owner

evanw commented Nov 15, 2022

Thanks for the report. I'll fix this. In the meantime, you can use parentheses to work around this problem: infer A extends object => (infer A) extends object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants