From 243c9707d6e26b3de37d8eb5070413237a33708d Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Tue, 27 Jul 2021 15:26:54 +0300 Subject: [PATCH] Types: Change `context.chart` to plain `Chart` (#9477) --- types/index.esm.d.ts | 4 ++-- types/tests/scriptable.ts | 4 ++-- types/utils.d.ts | 9 --------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 0a3e1c28eaa..385c6359375 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 9a403cebf63..db72edb21ff 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 9896f2a7a35..309c1608c6b 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>>>;