-
Notifications
You must be signed in to change notification settings - Fork 45
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 support for useExperiment #30
Comments
@mr-piratman I would appreciate the type definition you used! |
Same issue here, |
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 }
} |
Expected Behavior
Support of
useExperiment
whenyarn add -D @types/marvelapp___react-ab-test
Current Behavior
not Supporting of
useExperiment
whenyarn 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 🍻
The text was updated successfully, but these errors were encountered: