Skip to content

Fix toggle type annotation refactors for unnamed types#515

Merged
mattiamanzati merged 1 commit intomainfrom
fix/toggle-type-annotation-unnamed
Dec 2, 2025
Merged

Fix toggle type annotation refactors for unnamed types#515
mattiamanzati merged 1 commit intomainfrom
fix/toggle-type-annotation-unnamed

Conversation

@mattiamanzati
Copy link
Contributor

Summary

  • Fixed toggle type annotation refactor to handle unnamed/unresolved types
  • Fixed toggle return type annotation refactor to handle unnamed/unresolved types
  • Added ts.NodeBuilderFlags.IgnoreErrors flag to allow type node generation even when types contain errors

Problem

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:

export const debug = Schema.Struct({
  id: Schema.Option(Schema.Number)
}).make

When attempting to toggle the type annotation, the refactor would fail because the .make accessor has complex unresolved types in its signature.

Solution

By adding the ts.NodeBuilderFlags.IgnoreErrors flag when calling typeToSimplifiedTypeNode, 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:

export const debug: (props: { readonly id: import("node_modules/effect/dist/dts/Option").Option<number> }, options?: Schema.MakeOptions) => { readonly id: import("node_modules/effect/dist/dts/Option").Option<number> } = Schema.Struct({
  id: Schema.Option(Schema.Number)
}).make

Test Plan

  • ✅ Added new test case toggleTypeAnnotation_unnamed.ts that verifies the refactor works with unnamed types
  • ✅ All existing tests pass
  • ✅ TypeScript compilation succeeds
  • ✅ Linting passes

🤖 Generated with Claude Code

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-bot
Copy link

changeset-bot bot commented Dec 2, 2025

🦋 Changeset detected

Latest commit: cbd84ce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/language-service Patch

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

@mattiamanzati mattiamanzati merged commit b77b7e5 into main Dec 2, 2025
3 checks passed
@mattiamanzati mattiamanzati deleted the fix/toggle-type-annotation-unnamed branch December 2, 2025 14:45
@github-actions github-actions bot mentioned this pull request Dec 2, 2025
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.

1 participant