-
-
Notifications
You must be signed in to change notification settings - Fork 2k
build: Enable TypeScript type checking #7680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
camdecoster
wants to merge
7
commits into
master
Choose a base branch
from
cam/7678/enable-typescript-type-checking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,021
−464
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4011faa
Linting/formatting
camdecoster d4425fc
Initial TS set up
camdecoster 71fc31c
Convert a few small files to TS
camdecoster 3c905c0
Update requires to handle esbuild ESM/CJS interoperability
camdecoster bbc1059
Use ts-node for scripts using TS that run outside of esbuild
camdecoster 116bf33
Run test script with ts-node
camdecoster 2439dad
Merge remote-tracking branch 'origin/master' into cam/7678/enable-typ…
camdecoster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ | |
| "schema": "node tasks/schema.mjs", | ||
| "stats": "node tasks/stats.js", | ||
| "find-strings": "node tasks/find_locale_strings.js", | ||
| "preprocess": "node tasks/preprocess.js", | ||
| "preprocess": "ts-node tasks/preprocess.js", | ||
| "use-draftlogs": "node tasks/use_draftlogs.js", | ||
| "empty-draftlogs": "node tasks/empty_draftlogs.js", | ||
| "empty-dist": "node tasks/empty_dist.js", | ||
|
|
@@ -40,12 +40,14 @@ | |
| "cibuild": "npm run empty-dist && npm run preprocess && node tasks/cibundle.mjs", | ||
| "lint": "npx @biomejs/biome lint", | ||
| "lint-fix": "npx @biomejs/biome format ./test/image/mocks --write; npx @biomejs/biome lint --write || true", | ||
| "typecheck": "tsc --noEmit", | ||
| "typecheck:watch": "tsc --noEmit --watch", | ||
| "pretest": "node tasks/pretest.js", | ||
| "test-jasmine": "karma start test/jasmine/karma.conf.js", | ||
| "test-mock": "node tasks/test_mock.mjs", | ||
| "test-image": "node test/image/compare_pixels_test.js", | ||
| "test-export": "node test/image/export_test.js", | ||
| "test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output", | ||
| "test-syntax": "ts-node tasks/test_syntax.js && npm run find-strings -- --no-output", | ||
| "test-bundle": "node tasks/test_bundle.js", | ||
| "test-plain-obj": "node tasks/test_plain_obj.mjs", | ||
| "test": "npm run test-jasmine -- --nowatch && npm run test-bundle && npm run test-image && npm run test-export && npm run test-syntax && npm run lint", | ||
|
|
@@ -122,6 +124,8 @@ | |
| "@biomejs/biome": "2.2.0", | ||
| "@plotly/mathjax-v2": "npm:[email protected]", | ||
| "@plotly/mathjax-v3": "npm:mathjax@^3.2.2", | ||
| "@types/d3": "3.5.34", | ||
| "@types/node": "^24.10.0", | ||
| "amdefine": "^1.0.1", | ||
| "assert": "^2.1.0", | ||
| "browserify-transform-tools": "^1.7.0", | ||
|
|
@@ -174,6 +178,8 @@ | |
| "through2": "^4.0.2", | ||
| "transform-loader": "^0.2.4", | ||
| "true-case-path": "^2.2.1", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.9.3", | ||
| "virtual-webgl": "^1.0.6" | ||
| }, | ||
| "overrides": { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 'use strict'; | ||
|
|
||
| import isNumeric from 'fast-isnumeric'; | ||
| import { BADNUM } from '../constants/numerical'; | ||
|
|
||
| // precompile for speed | ||
| const JUNK = /^['"%,$#\s']+|[, ]|['"%,$#\s']+$/g; | ||
|
|
||
| /** | ||
| * cleanNumber: remove common leading and trailing cruft | ||
| * Always returns either a number or BADNUM. | ||
| */ | ||
| function cleanNumber(v: any): number | undefined { | ||
| if (typeof v === 'string') v = v.replace(JUNK, ''); | ||
| if (isNumeric(v)) return Number(v); | ||
|
|
||
| return BADNUM; | ||
| } | ||
|
|
||
| export default cleanNumber; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 'use strict'; | ||
|
|
||
| const NUMBER_REGEX = '([2-9]|[1-9][0-9]+)?'; | ||
|
|
||
| /** | ||
| * make a regex for matching counter ids/names ie xaxis, xaxis2, xaxis10... | ||
| * | ||
| * @param head: the head of the pattern, eg 'x' matches 'x', 'x2', 'x10' etc. | ||
| * 'xy' is a special case for cartesian subplots: it matches 'x2y3' etc | ||
| * @param tail: a fixed piece after the id | ||
| * eg counterRegex('scene', '.annotations') for scene2.annotations etc. | ||
| * @param openEnded: if true, the string may continue past the match. | ||
| * @param matchBeginning: if false, the string may start before the match. | ||
| */ | ||
| export function counter(head: string, tail: string = '', openEnded: boolean, matchBeginning: boolean) { | ||
| const fullTail = tail + (openEnded ? '' : '$'); | ||
| const startWithPrefix = matchBeginning === false ? '' : '^'; | ||
| return head === 'xy' | ||
| ? new RegExp(startWithPrefix + 'x' + NUMBER_REGEX + 'y' + NUMBER_REGEX + fullTail) | ||
| : new RegExp(startWithPrefix + head + NUMBER_REGEX + fullTail); | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 'use strict'; | ||
|
|
||
| function sortObjectKeys(obj: Record<string, any>) { | ||
| return Object.keys(obj).sort(); | ||
| } | ||
|
|
||
| export default sortObjectKeys; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Types Directory | ||
|
|
||
| Centralized TypeScript type definitions for plotly.js. | ||
|
|
||
| ## Quick Import | ||
|
|
||
| ```typescript | ||
| // Import from main index (recommended) | ||
| import type { GraphDiv, Layout, PlotData } from '../types'; | ||
|
|
||
| // Or use path alias | ||
| import type { GraphDiv } from '@types'; | ||
| ``` | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ``` | ||
| types/ | ||
| ├── index.d.ts # Main export - import from here | ||
| ├── core/ # Core Plotly types (GraphDiv, Layout, Data, Config, Events) | ||
| ├── traces/ # Trace-specific types | ||
| ├── components/ # Component-specific types | ||
| ├── plots/ # Plot-specific types | ||
| └── lib/ # Utility types | ||
| ``` | ||
|
|
||
| ## Most Common Types | ||
|
|
||
| ### GraphDiv | ||
| ```typescript | ||
| import type { GraphDiv } from '../types'; | ||
|
|
||
| function draw(gd: GraphDiv): void { | ||
| const layout = gd._fullLayout; | ||
| const data = gd._fullData; | ||
| } | ||
| ``` | ||
|
|
||
| ### Layout | ||
| ```typescript | ||
| import type { Layout } from '../types'; | ||
|
|
||
| function updateLayout(layout: Partial<Layout>): void { | ||
| layout.title = 'New Title'; | ||
| } | ||
| ``` | ||
|
|
||
| ### PlotData (Traces) | ||
| ```typescript | ||
| import type { PlotData, ScatterTrace } from '../types'; | ||
|
|
||
| function processTrace(trace: PlotData): void { | ||
| if (trace.type === 'scatter') { | ||
| const scatter = trace as ScatterTrace; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Adding New Types | ||
|
|
||
| 1. Create file in appropriate subdirectory | ||
| 2. Export from `index.d.ts` | ||
| 3. Use in your TypeScript files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Common component-related types | ||
| * | ||
| * Types shared across different component modules | ||
| */ | ||
|
|
||
| /** | ||
| * Component module interface | ||
| */ | ||
| export interface ComponentModule { | ||
| includeBasePlot?: (basePlotModule: string) => void; | ||
| layoutAttributes?: any; | ||
| name: string; | ||
| supplyLayoutDefaults?: (layoutIn: any, layoutOut: any, fullData: any) => void; | ||
| } | ||
|
|
||
| /** | ||
| * Drawing options (used by many components) | ||
| */ | ||
| export interface DrawingOptions { | ||
| duration?: number; | ||
| ease?: string; | ||
| redraw?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * SVG text utilities return type | ||
| */ | ||
| export interface TextBBox { | ||
| bottom: number; | ||
| height: number; | ||
| left: number; | ||
| right: number; | ||
| top: number; | ||
| width: number; | ||
| } | ||
|
|
||
| /** | ||
| * Color with alpha | ||
| */ | ||
| export type ColorString = string; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.