Skip to content

fix(types): export the generated Data union instead of a deleted module - #8002

Closed
jcampbell wants to merge 1 commit into
plotly:mainfrom
jcampbell:fix/data-type-dangling-reexport
Closed

fix(types): export the generated Data union instead of a deleted module#8002
jcampbell wants to merge 1 commit into
plotly:mainfrom
jcampbell:fix/data-type-dangling-reexport

Conversation

@jcampbell

Copy link
Copy Markdown

Problem

lib/index.d.ts re-exports Data from src/types/core/data:

export type { Data } from '../src/types/core/data';

That file was removed in 1f1898e ("refactor: Generate data type union instead of hand writing"), which moved the union into src/types/generated/schema.d.ts. The commit repointed the five importers under src/types/, but missed lib/index.d.ts and src/types/core/data.internal.d.ts.

The entry point already does export type * from '../src/types/generated/schema', which supplies the generated Data. But an explicit named re-export takes precedence over a star re-export, so the dangling line shadows the working union — and because the module it names doesn't exist, Data resolves to any for every consumer.

This is silent in practice. skipLibCheck: true is the default in most application tsconfigs (and in tsc --init), which suppresses the unresolved-module error inside the declaration file. The result is that traces annotated Data — the primary public type of the library — are simply unchecked, with nothing to indicate it.

Reproduction

Against plotly.js@4.0.0 from npm, with strict: true and skipLibCheck: true:

import type { Data, Layout } from 'plotly.js';

declare const d: Data;
declare const l: Layout;

const n: number = d;              // no error  ← should error
const s = d.nonexistentProperty;  // no error  ← should error
const m: number = l;              // errors correctly (control)

Layout and Config behave correctly, which is what makes the Data case easy to miss.

Fix

  • Drop the dangling re-export from lib/index.d.ts; the star re-export of the generated schema already exports Data.
  • Repoint src/types/core/data.internal.d.ts at ../generated/schema (it imports Data to build FullData), and update the stale doc comment pointing at data.d.ts.

Verification

Both lines above now error as expected. With skipLibCheck: false, Data and FullData both resolve and no dangling-module errors remain.

Found while migrating an app from @types/plotly.js to the declarations plotly.js 4 now ships. The migration typechecked clean because of this bug; once Data resolved, it caught three real defects in our own code.

🤖 Generated with Claude Code

…dule

`lib/index.d.ts` re-exported `Data` from `src/types/core/data`, which was
removed in 1f1898e ("refactor: Generate data type union instead of hand
writing"). That commit repointed the five importers under `src/types/`, but
`lib/index.d.ts` and `src/types/core/data.internal.d.ts` were missed.

The entry point already re-exports the generated schema with `export type *`,
and the generator now emits `Data` there. An explicit named re-export takes
precedence over a star re-export, so the dangling line shadowed the working
union and `Data` resolved to `any` for every consumer. `skipLibCheck: true` —
the default in most app tsconfigs — hides the unresolved module, so the failure
is silent: traces annotated `Data` are simply unchecked.

Reproduced against plotly.js 4.0.0 from npm:

    import type { Data } from 'plotly.js';
    declare const d: Data;
    const n: number = d;              // no error
    const s = d.nonexistentProperty;  // no error

Both now error as expected, and `FullData` resolves with `skipLibCheck: false`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@camdecoster

Copy link
Copy Markdown
Contributor

Thanks for the PR! This is actually being fixed in #8000, so I'm going to close this one. But I missed the docstring update, so I'll add that to mine. Good catch!

@camdecoster camdecoster closed this Sep 1, 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.

2 participants