Skip to content

feat: fall back to type checker for non-generic type aliases with unresolvable utility types#2513

Open
puckey wants to merge 2 commits into
vega:nextfrom
puckey:feat/type-checker-fallback
Open

feat: fall back to type checker for non-generic type aliases with unresolvable utility types#2513
puckey wants to merge 2 commits into
vega:nextfrom
puckey:feat/type-checker-fallback

Conversation

@puckey

@puckey puckey commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • For non-generic type aliases like Awaited<ReturnType<typeof fn>>, AST-based parsing can fail when utility types can't be resolved structurally, producing "Failed to correctly infer type"
  • Pre-resolves these aliases via the type checker before AST parsing, then falls back to the resolved type node when an errored UnknownType is detected
  • Uses InTypeAlias and NoTruncation flags to produce complete synthesized nodes
  • Sets parent references on synthesized nodes lazily (only when fallback fires)
  • Wraps fallback in try/catch with quality check — only keeps the fallback if it resolves without errors

Test plan

  • type-awaited-return-type-inferred — object return type
  • type-awaited-return-type-array — array return type
  • type-awaited-return-type-union — discriminated union return type
  • type-awaited-return-type-nested-ref — nested interface reference
  • type-awaited-return-type-primitivestring | undefined return type
  • type-awaited-return-type-break — function-valued properties (graceful degradation)
  • All existing tests pass

@puckey puckey marked this pull request as draft March 30, 2026 12:45
@puckey puckey force-pushed the feat/type-checker-fallback branch from ec0c347 to aa0ad32 Compare March 30, 2026 13:49
@puckey puckey marked this pull request as ready for review March 30, 2026 13:51

@arthurfiorette arthurfiorette left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each unit test takes a bit to run, can you join your tests into less files? No need to have 5 separate file tests for this PR. Also, only add tsconfig in the tests you need.

@puckey puckey force-pushed the feat/type-checker-fallback branch from aa0ad32 to e90efcc Compare March 31, 2026 07:04
@puckey

puckey commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

Merged tests, rebased on next and ran tests.

@puckey puckey requested a review from arthurfiorette April 2, 2026 18:39
@arthurfiorette arthurfiorette enabled auto-merge (squash) June 18, 2026 23:45
auto-merge was automatically disabled June 19, 2026 07:37

Head branch was pushed to by a user without write access

@puckey

puckey commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Same TS6 moduleResolution deprecation as the others — fixed in 0e5f3d4.

puckey added 2 commits June 19, 2026 13:27
…esolvable utility types

- Pre-resolve non-generic type aliases via the type checker before AST parsing
- Fall back to resolved type node when AST parsing produces errored UnknownType
- Use InTypeAlias and NoTruncation flags to produce complete synthesized nodes
- Set parent references on synthesized nodes lazily (only on fallback)
- Wrap fallback in try/catch with quality check to prevent degraded schemas
- Handle unresolved ReferenceType in hasErroredUnknown
- Add test for Awaited<ReturnType<typeof fn>> with object, array, union,
  nested-ref, primitive, and function-property return types
Use non-deprecated moduleResolution (node -> bundler) and regenerate
schema.json for the TS6 union member ordering of string | undefined.
@puckey puckey force-pushed the feat/type-checker-fallback branch from 0e5f3d4 to c2719ae Compare June 19, 2026 11:34
@puckey

puckey commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto next and regenerated the fixture schema for TS6's string | undefined union ordering (c2719ae).

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

Successfully merging this pull request may close these issues.

2 participants