Skip to content

Keep the .d.ts-only types of a package compiled from its JavaScript - #1729

Merged
ctate merged 4 commits into
mainfrom
ctate/keep-d-ts-8bbef6
Oct 22, 2026
Merged

ctate merged 4 commits into
mainfrom
ctate/keep-d-ts-8bbef6

Conversation

@ctate

@ctate ctate commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator
  • Interfaces, type aliases and enums that only a package's .d.ts declares resolved to any when the package compiled from its JavaScript, so declarations using them took the initializer's type.
  • The declaration files stay available as copies, and the runtime entry gains a JSDoc typedef for each type-only export.
  • Adds corpus program 7001-package-declared-types.

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 22, 2026 5:35am UTC

Comment thread packages/compiler/src/frontend/npm-static-type-exports.ts
Comment thread packages/compiler/src/frontend/npm-static.ts Outdated
The compiler compiles itself natively, and an empty array in an object
literal took number[] there, so the enum entry did not match the
declaration record. The coverage snapshot of native-npm-imports now
counts one dynamic-tier statement instead of three: the program's
`const point: Vector` takes the interface from the package's .d.ts
instead of any.
… and .mjs entries

- A local `export { Kind }` of a name the declaration file imports
  (`import type { Kind } from "./kinds"`) now resolves like
  `export { Kind } from "./kinds"`; it was dropped.
- The typedefs now reach a runtime entry outside the .js/.cjs rewrite
  path (an .mjs file).
- Only data shapes are re-exported: an interface, type alias or enum
  with no method, call or construct signature, function type or other
  computed type, whose referenced types are data shapes too. An
  interface with methods describes the package's JavaScript objects and
  stays as the JavaScript types it (@opentelemetry/api's Counter).
- NPM_STATIC_TYPES_SUFFIX moves to npm-static.ts, so that module does
  not import the syntax modules (the self-hosted frontend tests compile
  it natively).
Comment thread packages/compiler/src/frontend/npm-static-type-exports-host.ts Outdated
…ata shape

The data-shape check answered a type that refers back to a type still
being checked as a data shape and recorded that answer before the
outer check finished. With `Branch { child: Tree; handle: Handle }` and
`Tree { parent: Branch | null }`, checking Branch first recorded Tree as
a data shape, and Tree was re-exported although Branch reaches an
interface with a method. The check now walks every type reachable from
the queried one before it records any of them as a data shape, and
records the types on the path to a non-data type as non-data.
@ctate
ctate merged commit e597e2d into main Oct 22, 2026
63 of 64 checks passed
@ctate
ctate deleted the ctate/keep-d-ts-8bbef6 branch October 22, 2026 05:38

This branch was successfully deployed

1 active deployment
Preview — 47ba594c Deployed Oct 22, 2026 by vercel[bot]
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.

1 participant