]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Types: Change `context.chart` to plain `Chart` (#9477)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Tue, 27 Jul 2021 12:26:54 +0000 (15:26 +0300)
committerGitHub <noreply@github.com>
Tue, 27 Jul 2021 12:26:54 +0000 (08:26 -0400)
types/index.esm.d.ts
types/tests/scriptable.ts
types/utils.d.ts

index 0a3e1c28eaabbc94f45c6b52b4d3befb0f51548b..385c63593750cbda23da4995cb666728f53b965d 100644 (file)
@@ -1,4 +1,4 @@
-import { DeepPartial, DistributiveArray, IntersectItems, UnionToIntersection } from './utils';
+import { DeepPartial, DistributiveArray, UnionToIntersection } from './utils';
 
 import { TimeUnit } from './adapters';
 import { AnimationEvent } from './animation';
@@ -17,7 +17,7 @@ export { LayoutItem, LayoutPosition } from './layout';
 
 export interface ScriptableContext<TType extends ChartType> {
   active: boolean;
-  chart: IntersectItems<Chart<TType>>;
+  chart: Chart;
   dataIndex: number;
   dataset: UnionToIntersection<ChartDataset<TType>>;
   datasetIndex: number;
index 9a403cebf63ccf19c36d0c3ec65a661d47b8e261..db72edb21ff202a6dca1813a2c917fe7307edd85 100644 (file)
@@ -10,9 +10,9 @@ interface test {
 }
 
 const testImpl: test = {
-  pie: (ctx) => ctx.parsed,
+  pie: (ctx) => ctx.parsed + ctx.chart.width,
   line: (ctx) => ctx.parsed.x + ctx.parsed.y,
-  testA: (ctx) => ctx.parsed,
+  testA: (ctx) => ctx.parsed + ctx.dataset.data[0],
   testB: (ctx) => ctx.parsed.x + ctx.parsed.y,
   // @ts-expect-error combined type should not be any
   testC: (ctx) => ctx.fail,
index 9896f2a7a351dce4fb334c9b4dc6b66039fafcce..309c1608c6bf9d207f8948c9e2b743ba59d6eee0 100644 (file)
@@ -19,12 +19,3 @@ export type DistributiveArray<T> = [T] extends [unknown] ? Array<T> : never
 // https://stackoverflow.com/a/50375286
 export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
 
-// https://stackoverflow.com/a/59463385
-type TupleKeys<T extends unknown> = Exclude<keyof T, keyof []>
-type Foo<T extends unknown> = {
-    [K in TupleKeys<T>]: {foo: T[K]}
-}
-type Values<T> = T[keyof T]
-type Unfoo<T> = T extends { foo: unknown } ? T['foo'] : never;
-
-export type IntersectItems<T extends unknown> = Unfoo<UnionToIntersection<Values<Foo<T>>>>;