marvelapp / react-ab-test

A/B testing React components and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for Mixpanel and Segment.com.
MIT License
243 stars 46 forks source link

Typescript types #11

Closed tbrannam closed 2 months ago

tbrannam commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

Is there anything in progress with this issue?

tbrannam commented 4 years ago

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

Aidurber commented 4 years ago

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:

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 commented 4 years ago

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

Any advances in this matter so far?