Fix toggle type annotation refactors for unnamed types#515
Merged
mattiamanzati merged 1 commit intomainfrom Dec 2, 2025
Merged
Fix toggle type annotation refactors for unnamed types#515mattiamanzati merged 1 commit intomainfrom
mattiamanzati merged 1 commit intomainfrom
Conversation
This commit fixes the toggle type annotation and toggle return type
annotation refactors to properly handle unnamed or unresolved types.
The issue occurred when trying to add type annotations to expressions
like `Schema.Struct({ ... }).make`, where the TypeScript compiler
couldn't resolve all the types in the signature. By adding the
`ts.NodeBuilderFlags.IgnoreErrors` flag, the type node generation
now succeeds even when the type contains errors or unresolved references.
Changes:
- Added IgnoreErrors flag to typeToSimplifiedTypeNode calls in annotate.ts
- Added IgnoreErrors flag to typeToSimplifiedTypeNode calls in toggleReturnTypeAnnotation.ts
- Added IgnoreErrors flag to typeToSimplifiedTypeNode calls in toggleTypeAnnotation.ts
- Added test case for unnamed types scenario
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: cbd84ce The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ts.NodeBuilderFlags.IgnoreErrorsflag to allow type node generation even when types contain errorsProblem
Previously, the toggle type annotation refactors would fail when trying to add type annotations to expressions where TypeScript couldn't fully resolve all types in the signature. A common example was:
When attempting to toggle the type annotation, the refactor would fail because the
.makeaccessor has complex unresolved types in its signature.Solution
By adding the
ts.NodeBuilderFlags.IgnoreErrorsflag when callingtypeToSimplifiedTypeNode, the TypeScript compiler now generates type nodes even when they contain errors or unresolved references. This allows the refactor to work correctly and produce valid type annotations:Test Plan
toggleTypeAnnotation_unnamed.tsthat verifies the refactor works with unnamed types🤖 Generated with Claude Code