benjamn / benjamn/ast-types

Removing TSPropertySignature node adds commas to the type declaration

Open
#653 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
194
Avg merge
22h 43m
Merged PRs (30d)
10

Description

I originally opened this issue on the jscodeshift project (facebook/jscodeshift#464), but I'm pretty sure it is originating on this library.
Basically when you try to remove a type property of a type definition you get unneeded commas like it was an object.
This only happens for typescript, if you use flow you have to use ObjectTypeProperty that works correctly.

Input:

```ts
type Props = {
__: translator;
form: Form;
isOpen: boolean;
closeModal: () => void;
};
```

Execute:

```ts
j(file.source).find(j.TSPropertySignature, { key: { name: "__" } }).remove();
```

Output:

```
type Props = {
form: Form;,
isOpen: boolean;,
closeModal: () => void;
};
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the provided TypeScript type definition and jscodeshift query that removes TSPropertySignature. Trace the removal and printing path for TypeScript properties, comparing it with the Flow ObjectTypeProperty behavior. Done means the remaining properties print with semicolons and no extra commas.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.