Skip to content
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

Types: Change context.chart to plain Chart #9477

Merged
merged 1 commit into from Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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';
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions types/tests/scriptable.ts
Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions types/utils.d.ts
Expand Up @@ -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>>>>;