Skip to content

applying fixes can create syntactically invalid code. #54

@bradzacher

Description

@bradzacher

I've been trying to use ts-fix to add annotations for isolatedDeclarations and I've run into a few cases where the fixers are not correctly merged together.

The most obvious example I've seen is when multiple imports need to be added from a module

// before fixing:
import type {
  A as B,
  C,
  D as E,
  F as H,
  H,
  I,
  J,
} from './mod1';

// after fixing -- syntax errors and duplicate imports
import type {
  A as B,
  C,
  D as E,
  F as H,
  H,
  I,
  J,
  H // missing commas
  I // missing commas
  J // missing commas
  K // missing commas
  L // missing commas
  M,
} from './mod1';
import { N } from './mod2';
import { JSX } from 'react/jsx-runtime';
import { O, P } from './mod3';
import { N } from './mod2'; // duplicate import

This of course makes at-scale codemodding difficult because many files will need to be fixed up by hand.


It's worth noting that if I manually open the file in VSCode and select the Add all missing type annotations quick fix:
quick fix
Then the resulting file is syntactically correct.
Which suggests that TS has a built-in mechanism for merging the fixes to produce valid code.

It would be great if we could switch to use this mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions