From: Jukka Kurkela Date: Tue, 27 Jul 2021 12:26:54 +0000 (+0300) Subject: Types: Change `context.chart` to plain `Chart` (#9477) X-Git-Tag: v3.5.1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=243c9707d6e26b3de37d8eb5070413237a33708d;p=thirdparty%2FChart.js.git Types: Change `context.chart` to plain `Chart` (#9477) --- diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 0a3e1c28e..385c63593 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -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 { active: boolean; - chart: IntersectItems>; + chart: Chart; dataIndex: number; dataset: UnionToIntersection>; datasetIndex: number; diff --git a/types/tests/scriptable.ts b/types/tests/scriptable.ts index 9a403cebf..db72edb21 100644 --- a/types/tests/scriptable.ts +++ b/types/tests/scriptable.ts @@ -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, diff --git a/types/utils.d.ts b/types/utils.d.ts index 9896f2a7a..309c1608c 100644 --- a/types/utils.d.ts +++ b/types/utils.d.ts @@ -19,12 +19,3 @@ export type DistributiveArray = [T] extends [unknown] ? Array : never // https://stackoverflow.com/a/50375286 export type UnionToIntersection = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never; -// https://stackoverflow.com/a/59463385 -type TupleKeys = Exclude -type Foo = { - [K in TupleKeys]: {foo: T[K]} -} -type Values = T[keyof T] -type Unfoo = T extends { foo: unknown } ? T['foo'] : never; - -export type IntersectItems = Unfoo>>>;