Skip to content

Update for typescript 5.4+ - #950

Closed
snowystinger wants to merge 1 commit into
benjamn:masterfrom
snowystinger:update-for-typescript
Closed

snowystinger wants to merge 1 commit into
benjamn:masterfrom
snowystinger:update-for-typescript

Conversation

@snowystinger

Copy link
Copy Markdown

Closes #948

benjamn added a commit that referenced this pull request Aug 30, 2026
* Fix lib/main.d.ts for TypeScript >= 5.4 with isolatedModules

src/main.ts imported Type, NodePath and builders and then declared
consts of the same names from the fork, so the emitted lib/main.d.ts
contained `import { Type } ...` followed by `declare const Type`.
TypeScript 5.4 rejects that combination under isolatedModules:

  error TS2865: Import 'Type' conflicts with local value, so must be
  declared with a type-only import when 'isolatedModules' is enabled.

Import the type meanings under different names and re-declare them next
to the consts, so the single `export { ... }` carries both meanings.
This uses only plain aliased imports, so no currently supported
TypeScript version loses support (checked against 3.9, 4.4, 4.9, 5.4 and
5.9). As a side effect, Type and NodePath imported from the package are
now usable as generic types, which they were not before.

Add script/consumer-typecheck, a minimal consumer of lib/main compiled by
run-tests.sh with both the pinned TypeScript and TypeScript 5.9 (installed
under the alias typescript5) with isolatedModules, so declaration-file
regressions like this one fail in CI. Without this fix that check reports
the three TS2865 errors above plus "Type 'NodePath' is not generic".

Fixes #948. Builds on #950.

* Type-check the consumer sample with TypeScript 4.4 as the supported floor

Add typescript@4.4.4 (the last release before inline `type` import
modifiers) alongside the pinned compiler and TypeScript 5.9, so
"supports TypeScript >= 4.4" is checked on every run rather than assumed.

The extra compilers move into script/consumer-typecheck's own
package.json, installed by run-tests.sh with `npm ci --prefix`. Keeping
them out of the root package matters: npm aliases of typescript all ship
a `tsc` bin, and the last one installed wins node_modules/.bin/tsc, which
`npm run build` uses. In the root that silently replaced the pinned
4.9.4 compiler with 4.4.4.
@benjamn

benjamn commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Thanks for tracking this down. Your diagnosis in #948 was exactly right, and it's now fixed on master by #959, which builds on this PR.

Two things kept me from merging this one as-is. import { type builders } collides with the const builders that main.ts destructures from the fork, so the value export disappears and the package no longer builds with the pinned TypeScript 4.9 (the test files fail with "Property 'builders' does not exist"). And inline type modifiers are TypeScript 4.5 syntax that lands verbatim in the shipped lib/main.d.ts, which would break consumers on TypeScript 4.4 and earlier.

#959 takes the aliasing route instead (import { Type as TypeClass } plus type Type<T> = TypeClass<T> next to the const), which needs nothing newer than TypeScript 2.3, and adds a consumer type-check to the test suite that runs under TypeScript 4.4, 4.9 and 5.9 with isolatedModules so this can't regress silently. The fix will ship in the next release. Closing in favour of #959.

@benjamn benjamn closed this Aug 30, 2026
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.

Type errors with TypeScript 5.4+

2 participants