Skip to content

Fix published type declarations for consumers with skipLibCheck off - #2175

Open
lukasIO wants to merge 1 commit into
mainfrom
claude/published-type-declarations-fix-124ebd
Open

lukasIO wants to merge 1 commit into
mainfrom
claude/published-type-declarations-fix-124ebd

Conversation

@lukasIO

@lukasIO lukasIO commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

The published declarations fail to type-check in a project with skipLibCheck: false. Thirteen source files import Throws from @livekit/throws-transformer/throws, and the type stays in the emitted .d.ts files. That package is a devDependency, so a consumer never installs it. PCTransport.d.ts uses sdp-transform types, but @types/sdp-transform is also a devDependency. With exactOptionalPropertyTypes on, two declarations also contradict each other. IDataTrack declares info?: DataTrackInfo, but the LocalDataTrack getter returns DataTrackInfo | undefined. LocalTrack declares processor?: TrackProcessor<…>, but LocalAudioTrack adds | undefined. Both entries are affected: dist/src and dist/core/types.

This change adds a local copy of Throws in src/utils/throws.ts and points the 13 imports at it. The transformer detects the type by its __throws brand, not by the module it comes from, so pnpm throws:check gives the same result. @types/sdp-transform moves to dependencies. IDataTrack.info and LocalTrack.processor are declared with | undefined. Without exactOptionalPropertyTypes, these are the same types.

The existing check:core script did not catch this, although it runs with skipLibCheck off. It runs inside the repo, so module resolution walks up to the repo's node_modules and finds the devDependencies. The new pnpm check:published-types script packs the built package and installs the tarball with npm into a temp directory outside the repo. Then it type-checks all four type entries with strict, skipLibCheck: false and exactOptionalPropertyTypes. CI runs it in test.yaml after build:clean.

No runtime code changes. Consumers get one more types-only dependency, @types/sdp-transform.

Fixes #2164

🤖 Generated with Claude Code

The declarations imported `Throws` from @livekit/throws-transformer and
used sdp-transform types, but both type packages were devDependencies, so
consumers that check library types could not resolve them. Two optional
properties also conflicted with their overrides under
exactOptionalPropertyTypes.

- copy the `Throws` type into src/utils/throws.ts (the transformer matches
  its `__throws` brand, not the import path)
- move @types/sdp-transform to dependencies
- declare IDataTrack.info and LocalTrack.processor as `| undefined`
- add check:published-types, which type-checks the packed tarball in a
  temp project outside the repo, and run it in CI

Fixes #2164

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 115.86 KB (0%)
dist/livekit-client.umd.js 125.1 KB (0%)
dist/core/core.mjs 78.57 KB (+0.03% 🔺)

@changeset-bot

changeset-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fd1ede4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Comment thread src/utils/throws.ts
Comment on lines +1 to +15
// A copy of `Throws` from `@livekit/throws-transformer/throws`. The published declarations name
// this type, and the transformer is a devDependency, so a consumer could not resolve an import
// of it. The transformer matches the `__throws` brand, not the import path: keep the brand as is.

type Primitives = void | null | undefined | string | number | bigint | boolean | symbol;

/**
* Branded type that encodes possible thrown errors in the return type. The error types are
* phantom types for static analysis; the runtime value is just T.
*/
export type Throws<T, E extends Error> =
| (T & {
readonly __throws?: E;
})
| Extract<T, Primitives>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Is there some way these could pull from the npm package implementation still, but get resolved at build time into effectively the contents of this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, I'm not particularly happy about just copying this either.

The potential viable options as I see them:

  • have a dedicated types package for the throws transformer that's installed as a regular dependency
  • keep the copy and add a build time check that the types actually match

This branch has not been deployed

No deployments
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.

Published type declarations fail for consumers that check library types (skipLibCheck: false)

2 participants