typescript support for useExperiment
Expected Behavior
Support of useExperiment when
yarn add -D @types/marvelapp___react-ab-test
Current Behavior
not Supporting of useExperiment when
yarn add -D @types/marvelapp___react-ab-test
I wrote a type definition for myself so if anyone wants it just let me know. but I would happy to have it out of the box.
thanks 🍻
Expected Behavior
Support of
useExperimentwhenyarn add -D @types/marvelapp___react-ab-testCurrent Behavior
not Supporting of
useExperimentwhenyarn add -D @types/marvelapp___react-ab-testI wrote a type definition for myself so if anyone wants it just let me know. but I would happy to have it out of the box.
thanks 🍻
@mr-piratman I would appreciate the type definition you used!
Same issue here, useExperiment doesn't seem to be exported from the package.
eventually, I add
// Type definitions for @marvelapp/react-ab-test 3.1
// Project: https://github.com/marvelapp/react-ab-test#readme
// Definitions by: mtayllan <https://github.com/mtayllan>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="react" />
declare module '@marvelapp/react-ab-test' {
export type ListenerCallback = (experimentName: string, variantName: string) => void;
export interface Subscription {
remove(): void;
listener: ListenerCallback;
eventType: string;
}
export namespace emitter {
function emitWin(experimentName: string): void;
function addActiveVariantListener(eventName: (string | ListenerCallback), callback?: ListenerCallback): Subscription;
function addPlayListener(eventName: (string | ListenerCallback), callback?: ListenerCallback): Subscription;
function addWinListener(eventName: (string | ListenerCallback), callback?: ListenerCallback): Subscription;
function defineVariants(experimentName: string, variantNames: string[], variantWeights?: number[]): void;
function setActiveVariant(experimentName: string, variantName: string): void;
function getActiveVariant(experimentName: string): string;
function calculateActiveVariant(experimentName: string, userIdentifier?: string, defaultVariantName?: string): string;
function getSortedVariants(experimentName: string): string[];
function setCustomDistributionAlgorithm(customAlgorithm: (experimentName: string, userIdentifier: string, defaultVariantName?: string) => void): void;
}
export interface ExperimentProps {
name: string;
defaultVariantName?: string;
userIdentifier?: string;
children: React.ReactNode;
}
export function Experiment({
name, defaultVariantName, userIdentifier, children,
}: ExperimentProps): JSX.Element;
export function Variant({
name,
children,
}: { name: string, children: React.ReactNode }): JSX.Element;
export namespace experimentDebugger {
function setDebuggerAvailable(isAvailable: boolean): void;
function enable(): void;
function disable(): void;
}
export namespace mixpanelHelper {
function enable(): void;
function disable(): void;
}
export namespace segmentHelper {
function enable(): void;
function disable(): void;
}
export function emitWin(): void;
export function selectVariant<T extends Record<string, any>>(variants: T): T[keyof T];
export function useExperiment(key: string): { emitWin: typeof emitWin, selectVariant: typeof selectVariant }
}