react-ab-test icon indicating copy to clipboard operation
react-ab-test copied to clipboard

Typescript types

Open tbrannam opened this issue 5 years ago • 6 comments

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?

tbrannam avatar Sep 11 '19 16:09 tbrannam

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?

moretti avatar Sep 12 '19 10:09 moretti

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

tbrannam avatar Sep 12 '19 14:09 tbrannam

Is there anything in progress with this issue?

dotorimook avatar Feb 11 '20 04:02 dotorimook

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

tbrannam avatar Feb 23 '20 05:02 tbrannam

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()
}

Aidurber avatar Jul 09 '20 13:07 Aidurber

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

Any advances in this matter so far?

brucruz avatar Aug 07 '20 20:08 brucruz