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

Add TypeScript? #10

Open
felipefialho opened this issue Sep 17, 2019 · 5 comments
Open

Add TypeScript? #10

felipefialho opened this issue Sep 17, 2019 · 5 comments

Comments

@felipefialho
Copy link

I've been adding a TypeScript interface to use funnel-graph-js in my project. Follows the code if you want to create a TypeScript version here 😄

export interface IFunnelGraph {
  container: string;
  gradientDirection: 'horizontal' | 'vertical';
  data: {
    colors: string[];
    labels: string[];
    values: number[];
  };
  displayPercent: boolean;
  direction: 'horizontal' | 'vertical';
  height: number;
  width: number;
  subLabelValue: 'percent' | 'raw';
  draw: () => {};
  makeVertical: () => {};
  makeHorizontal: () => {};
  toggleDirection: () => {};
  gradientMakeVertical: () => {};
  gradientMakeHorizontal: () => {};
  gradientToggleDirection: () => {};
  updateHeight: () => {};
  updateWidth: () => {};
  updateData: (data: any) => {};
  update: (options: any) => {};
}

Thanks for your project ❤️

@felipefialho felipefialho changed the title Add typescript? Add TypeScript? Sep 17, 2019
@greghub
Copy link
Owner

greghub commented Sep 17, 2019

Hi @felipefialho , thank you very much! I have no TypeScript experience, is it possible to incorporate your code somehow in the library to make it usable for both JS and TS?

@muriloamendola
Copy link

Hi @greghub, answering your question... Yes! You can code your library to make it usable for JS and TS. The following article has a good explanation about how to do that: https://medium.com/cameron-nokes/the-30-second-guide-to-publishing-a-typescript-package-to-npm-89d93ff7bccd

@yourtraffix
Copy link

any update for Typescript support?

@maitrungduc1410
Copy link

waiting for this

@elektronik2k5
Copy link

Here's what worked for me, based on @felipefialho's work above:

declare module 'funnel-graph-js' {
  class IFunnelGraph {
    color: string;
    container: string;
    gradientDirection: 'horizontal' | 'vertical';
    data: {
      colors: string[];
      labels: string[];
      values: number[];
    };
    displayPercent: boolean;
    direction: 'horizontal' | 'vertical';
    height: number;
    width: number;
    subLabelValue: 'percent' | 'raw';
    draw: () => {};
    makeVertical: () => {};
    makeHorizontal: () => {};
    toggleDirection: () => {};
    gradientMakeVertical: () => {};
    gradientMakeHorizontal: () => {};
    gradientToggleDirection: () => {};
    updateHeight: () => {};
    updateWidth: () => {};
    updateData: (data: any) => {};
    update: (options: any) => {};
    constructor(options: Partial<IFunnelGraph>);
  }

  export default IFunnelGraph;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants