⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@camdecoster
Copy link
Contributor

@camdecoster camdecoster commented Jan 2, 2026

Description

Enable TypeScript type checking.

Closes #7678.

Changes

  • Add limited set of plotly.js types
  • Enable type checking
  • Update some files to TypeScript
  • Use ts-node for running some scripts

Testing

  • CI should cover everything
  • Run npm run build locally to check that everything is bundled properly by esbuild
  • Run plotly.js devtools and load some mocks to make sure everything is working correctly
  • Run npm run typecheck to perform a type check on the source code. There should be no errors:
    $ npm run typecheck
    
    > [email protected] typecheck
    > tsc --noEmit
    $

Notes

  • This PR adds the TypeScript compiler and typechecking via npm script
  • The provided types are a combination of plotly.js types from DefinitelyTyped and the schema (with Claude combining the two). This is a first pass and the types will need to be updated as files are converted.
  • (Most) IDEs will read the types and provide autocompletion once files are converted over
  • Read the README in src/types for an overview of how the types are set up
  • esbuild is compatible with TypeScript already, but it doesn't do type checking. To check types you need to run npm run typecheck. VS Code will also provide feedback as you're editing files.
  • I converted a few simple files to TypeScript as an example. I opted to use ESM syntax for these files which necessitated some changes in the require statements for the converted files. This is due to how esbuild determines if a default import should be namespaced or not.
  • Some of the converted files are used in scripts not processed by esbuild. Node 18 doesn't handle TS files natively, so these scripts need to be run with ts-node, a "TypeScript execution and REPL for node.js".
  • The TS config is pretty lenient right now to make it easier to convert things piece by piece. Once we make enough progress, this can be tightened up.
  • TS is not emitting files/types right now. esbuild handles converting the TS so the TS compiler won't need to do that. It would be valuable to have the compiler write the type definition files in the future.

@camdecoster camdecoster changed the title build: Enable typescript type checking build: Enable TypeScript type checking Jan 2, 2026
@camdecoster camdecoster marked this pull request as ready for review January 2, 2026 23:54
var constants = require('./constants');
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var sortObjectKeys = require('../../lib/sort_object_keys');
var sortObjectKeys = require('../../lib/sort_object_keys').default;
Copy link
Contributor

Choose a reason for hiding this comment

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

@camdecoster Is it worth considering moving away from default exports entirely as part of this transition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only matters when one mixes CJS and ESM. That said, I don't think that we can avoid that for a long time. I suppose we could make just pick a direction to go and standardize. I could go either way, but the esbuild docs make it clear that they don't like default exports.

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.

[FEATURE]: Add TypeScript type checking

3 participants