Skip to content

Commit

Permalink
fix(types): add types for Chart interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Aug 17, 2023
1 parent 328aeea commit acd81b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/api/chart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { extend } from './extend';
import { G2Spec } from 'spec';
import { extend, API } from './extend';
import { library } from './library';
import { Runtime } from './runtime';

// Use a empty interface to mark Chart both a value and a class type.
export interface Chart {}
export interface Chart extends API<G2Spec, typeof library> {}

export const Chart = extend(Runtime, library);
8 changes: 5 additions & 3 deletions src/api/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type CompositionOf<Library> = Of<
CompositionOf<Library>
>;

export type API<Spec, Library> = Runtime<Spec> &
MarkOf<Library, (composite?) => MarkNode> &
CompositionOf<Library>;

export function extend<
Spec extends G2Spec = G2Spec,
Library extends G2Library = G2Library,
>(
Runtime: new (options: RuntimeOptions) => Runtime<Spec>,
library: Library,
): new (options?: RuntimeOptions) => Runtime<Spec> &
MarkOf<Library, (composite?) => MarkNode> &
CompositionOf<Library> {
): new (options?: RuntimeOptions) => API<Spec, Library> {
class Chart extends Runtime {
constructor(options: Omit<RuntimeOptions, 'lib'>) {
super({ ...options, lib: library });
Expand Down

0 comments on commit acd81b9

Please sign in to comment.