From 6757c5a9f878da1947f5c02398caf759812e8dcf Mon Sep 17 00:00:00 2001 From: Junyao Chen Date: Tue, 27 Jun 2023 11:27:20 -0400 Subject: [PATCH] stats: Install @types/plotly.js for type check. This is a prep commit for typescript migration for `stats.js`, which used a third party module `plotly.js` that doesn't come with types. --- package.json | 1 + pnpm-lock.yaml | 7 +++++++ tools/test-js-with-node | 1 + version.py | 2 +- web/src/plotly.js.d.ts | 19 +++++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 web/src/plotly.js.d.ts diff --git a/package.json b/package.json index ce0841cd8d..0c5ca9f28a 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "@types/micromodal": "^0.3.3", "@types/minimalistic-assert": "^1.0.1", "@types/node": "^18.8.3", + "@types/plotly.js": "^2.12.20", "@types/sortablejs": "^1.15.1", "@types/turndown": "^5.0.1", "@typescript-eslint/eslint-plugin": "^6.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6ae01cc3e..40b28bb2a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -298,6 +298,9 @@ devDependencies: '@types/node': specifier: ^18.8.3 version: 18.16.20 + '@types/plotly.js': + specifier: ^2.12.20 + version: 2.12.20 '@types/sortablejs': specifier: ^1.15.1 version: 1.15.1 @@ -2987,6 +2990,10 @@ packages: resolution: {integrity: sha512-O397rnSS9iQI4OirieAtsDqvCj4+3eY1J+EPdNTKuHuRWIfUoGyzX294o8C4KJYaLqgSrd2o60c5EqCU8Zv02g==} dev: true + /@types/plotly.js@2.12.20: + resolution: {integrity: sha512-ZDNAde0VqBCrcgmQQyOmWM71k1+5oWaNkfliZ4ix5IdBkjbLye1S6JIdw+XFWGAIeimpjnkLsLzMOwQ105eIOg==} + dev: true + /@types/qs@6.9.7: resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==} diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 856d54afa2..20469f24ac 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -132,6 +132,7 @@ EXEMPT_FILES = make_set( "web/src/overlays.ts", "web/src/padded_widget.ts", "web/src/page_params.ts", + "web/src/plotly.js.d.ts", "web/src/pm_list.js", "web/src/pm_list_dom.js", "web/src/poll_widget.js", diff --git a/version.py b/version.py index 048d143409..5a4629ac2a 100644 --- a/version.py +++ b/version.py @@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 203 # historical commits sharing the same major version, in which case a # minor version bump suffices. -PROVISION_VERSION = (246, 1) +PROVISION_VERSION = (246, 2) diff --git a/web/src/plotly.js.d.ts b/web/src/plotly.js.d.ts new file mode 100644 index 0000000000..cf30165a03 --- /dev/null +++ b/web/src/plotly.js.d.ts @@ -0,0 +1,19 @@ +// An internal type extracted from @types/plotly.js +// pie and bar are both trace modules from the traces subdirectory +type TraceModule = { + [key: string]: unknown; + moduleType: "trace"; + name: string; + categories: string[]; + meta: Record; +}; + +declare module "plotly.js/lib/pie" { + const PlotlyPie: TraceModule; + export = PlotlyPie; +} + +declare module "plotly.js/lib/bar" { + const PlotlyBar: TraceModule; + export = PlotlyBar; +}