Skip to content

Make knip compatible with erasableSyntaxOnly#1541

Merged
webpro merged 3 commits intowebpro-nl:mainfrom
wojtekmaj:erasable-syntax
Feb 19, 2026
Merged

Make knip compatible with erasableSyntaxOnly#1541
webpro merged 3 commits intowebpro-nl:mainfrom
wojtekmaj:erasable-syntax

Conversation

@wojtekmaj
Copy link
Copy Markdown
Contributor

@wojtekmaj wojtekmaj commented Feb 18, 2026

By making knip compatible with erasableSyntaxOnly, we're making knip compatible with other systems that could potentially parse or transpile knip codebase, but are unable (or rather: unwilling) to parse TS features that require JS emit changes.

For example, we could:

  • replace tsc with another compiler like swc
  • drop tsx dependency from knip repository (Node.js supports TypeScript natively, but with erasable syntax only)
    • Making smoke tests significantly faster in the process

This change also eliminates a whole class of potential bugs related to enums, namespaces legacy decorators and other syntax this setting is forbidding.

By making knip compatible with erasableSyntaxOnly, we're making knip compatible with other systems that could potentially parse or transpile knip codebase.

For example, we could:
- replace `tsc` with another compiler like swc
- drop `tsx` dependency from knip repository (Node.js supports TypeScript natively, but with erasable syntax only)

This change also eliminates a whole class of potential bugs related to enums, namespaces legacy decorators and other syntax this setting is forbidding.
Copilot AI review requested due to automatic review settings February 18, 2026 09:48
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/knip@1541
npm i https://pkg.pr.new/@knip/language-server@1541
npm i https://pkg.pr.new/@knip/mcp@1541

commit: ca30458

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables the erasableSyntaxOnly TypeScript compiler option for the knip package, making it compatible with alternative TypeScript parsers/transpilers like swc and Node.js native TypeScript support. This change restricts the codebase to use only "erasable" TypeScript syntax that doesn't require JavaScript emit transformations.

Changes:

  • Enabled erasableSyntaxOnly in tsconfig.json compiler options
  • Converted enum CharacterCodes to a const object in ast-helpers.ts
  • Refactored constructor parameter properties to explicit private field declarations in three Peeker classes (YamlCatalogPeeker, PackagePeeker, JsonCatalogPeeker)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/knip/tsconfig.json Adds erasableSyntaxOnly: true to compiler options
packages/knip/src/typescript/ast-helpers.ts Converts CharacterCodes enum to const object with property syntax
packages/knip/src/YamlCatalogPeeker.ts Removes constructor parameter property, adds explicit private field
packages/knip/src/PackagePeeker.ts Removes constructor parameter property, adds explicit private field
packages/knip/src/JsonCatalogPeeker.ts Removes constructor parameter property, adds explicit private field

…peScript version

This setting is just a safeguard, so removing it does not change the output in any way and is safe for testing purposes. Without this change, older TypeScript versions throw with "Unknown compiler option 'erasableSyntaxOnly'.".
wojtekmaj added a commit to wojtekmaj/knip that referenced this pull request Feb 18, 2026
This draft PR is to showcase the potential behind webpro-nl#1541.

Local results are promising:

Old test results:

```
ℹ tests 245
ℹ suites 0
ℹ pass 245
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 43892.244416
```

```
ℹ tests 324
ℹ suites 1
ℹ pass 323
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 48137.8335
```

Old log output (fragment):
```
wojciech.maj@MacBook-Pro knip % pnpm test:smoke

> knip@5.83.1 test:smoke /Users/wojciech.maj/Projekty/Open source projects/knip/packages/knip
> glob-bin -c "tsx --test" "test/*.test.ts" && glob-bin -c "tsx --test" "test/{plugins,util}/*.test.ts"

✔ Should handle empty named catalog entries without null pointer error (344.005667ms)
✔ Should track referenced catalog entries (package.json) (128.936166ms)
✔ Should track referenced catalog entries (package.json root) (69.343ms)
✔ Should track referenced default catalog entries (177.375916ms)
✔ Should track referenced named catalog entries (37.006291ms)
✔ Should track referenced default catalog entries (171.729875ms)
```

New test results:

```
ℹ tests 245
ℹ suites 0
ℹ pass 245
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 39849.829583
```

```
ℹ tests 324
ℹ suites 1
ℹ pass 322
ℹ fail 2
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 37563.619541
```

New log output (fragment):
```
wojciech.maj@MacBook-Pro knip % pnpm test:smoke-fast

> knip@5.83.1 test:smoke-fast /Users/wojciech.maj/Projekty/Open source projects/knip/packages/knip
> glob-bin -c "node --import=./register.ts --test" "test/*.test.ts" && glob-bin -c "node --import=./register.ts --test" "test/{plugins,util}/*.test.ts"

✔ Should handle empty named catalog entries without null pointer error (96.482917ms)
✔ Should track referenced catalog entries (package.json) (74.104167ms)
✔ Should track referenced catalog entries (package.json root) (57.632125ms)
✔ Should track referenced default catalog entries (126.710542ms)
✔ Should track referenced named catalog entries (60.290042ms)
✔ Should track referenced default catalog entries (126.315625ms)
```
@webpro
Copy link
Copy Markdown
Member

webpro commented Feb 19, 2026

Great! I was also thinking of going .js.ts import specifier everywhere so we can run node src/cli.ts directly.

@webpro webpro merged commit f63089b into webpro-nl:main Feb 19, 2026
31 checks passed
@wojtekmaj
Copy link
Copy Markdown
Contributor Author

Great! I was also thinking of going .js.ts import specifier everywhere so we can run node src/cli.ts directly.

Yes, I think that's a fantastic direction. Only it was too disruptive to just throw a PR at you without discussing first :D

@webpro
Copy link
Copy Markdown
Member

webpro commented Feb 21, 2026

🚀 This pull request is included in v5.85.0. See Release 5.85.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

3 participants