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

Typescript types #11

Open
tbrannam opened this issue Sep 11, 2019 · 6 comments
Open

Typescript types #11

tbrannam opened this issue Sep 11, 2019 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tbrannam
Copy link

I'm working on creating a typings file for this project. I'm curious if you would like to include this in the project - or should I plan on uploading to DefinitelyTyped?

@moretti
Copy link
Member

moretti commented Sep 12, 2019

I have some experience with Flow, but haven't used TypeScript.
I think it would be a great addition, typings can be helpful even when not writing in TypeScript for the IntelliSense support.
In terms of changes, we just need to publish a new directory with type definitions (index.d.ts) and then add a new types entry to package.json?

@tbrannam
Copy link
Author

yes - that's pretty much it - i'll look to complete that work in the coming weeks. I've got the very basics in so far

@dotorimook
Copy link

Is there anything in progress with this issue?

@tbrannam
Copy link
Author

I have two version i need to reconcile, should have time in the next couple weeks

@Aidurber
Copy link

Aidurber commented Jul 9, 2020

If anyone needs it ASAP, here's what I threw together this morning. It's not perfect but it'll get you going at least.

Be aware that it's missing:

  • Comments
  • MixPanel types
  • Segment types

There's probably a cleaner way to do the emitter and experiment debugger, but it works 🤷‍♂️

declare module '@marvelapp/react-ab-test' {
  import * as React from 'react'

  type ExperimentProps = {
    name: string
    userIdentifier?: string
    defaultVariantName?: string
  }

  type VariantProps = {
    name: string
  }

  export class Experiment extends React.Component<ExperimentProps, any> {}
  export class Variant extends React.Component<VariantProps, any> {}

  type EmitterCallback = (experimentName: string, variantName: string) => void

  type Subscription = {
    remove(): void
  }
  class Emitter {
    emitWin(experimentName: string): void
    addActiveVariantListener(experimentName?: string, callback: EmitterCallback): Subscription
    addPlayListener(experimentName?: string, callback: EmitterCallback): Subscription
    addWinListener(experimentName?: string, callback: EmitterCallback): Subscription
    defineVariants(
      experimentName: string,
      variantNames: string[],
      variantWeights: number[]
    ): void
    setActiveVariant(experimentName: string, variantName: string): void
    getActiveVariant(experimentName: string): string
    calculateActiveVariant(
      experimentName: string,
      userIdentifier?: string,
      defaultVariantName?: string
    ): string
    getSortedVariants(experimentName: string)
  }
  class ExperimentDebugger {
    setDebuggerAvailable(isAvailable: boolean): void
    enable(): void
    disable(): void
  }
  export const emitter = new Emitter()
  export const experimentDebugger = new ExperimentDebugger()
}

@brucruz
Copy link

brucruz commented Aug 7, 2020

I have two version i need to reconcile, should have time in the next couple weeks

Any advances in this matter so far?

@moretti moretti added enhancement New feature or request help wanted Extra attention is needed labels May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants