dsherret / dsherret/ts-morph

node.remove() missing from DeclareKeyword and ExportKeyword

Open
#1,366 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Describe the bug**

Version: 17.0.1

When trying to call the remove-Method ([following the docs](https://ts-morph.com/manipulation/removing)) on DeclareKeyword- or ExportKeyword-Nodes, the script will crash. Furthermore, the type guard is not able to narrow the type.

**To Reproduce**

```ts
import { ts } from "ts-morph";
// [....]
if (node.isKind(ts.SyntaxKind.ExportKeyword)) {
node.remove();
// ^-------- node wil be of type Node, instead of ExportKeyword.
// Will also crash, as it doesn't have a remove-Method
// Exception has occurred: TypeError: node.remove is not a function
}
```
**Expected behavior**

The type guard should be able to narrow the type of the node after using isKind, and the calling of remove() should not crash.

Contributor guide

Open the contributing guide

Research direction

Read CONTRIBUTING.md and the removing documentation, then reproduce the TypeScript snippet for DeclareKeyword and ExportKeyword. Trace the node and type definitions for both kinds and add coverage for the narrowed remove behavior; done means both guards narrow correctly and remove no longer throws.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.