import React from "react"; import { createFlags } from "../create-flags"; import { KeyPath, GetValueFromKeyPathString, KeyPathString } from "../types"; type Flags = { a: boolean; b: { c: { d: boolean; e: string; }; }; f: number; }; type Keys = KeyPath; type StringKeys = KeyPathString; it("check key paths", () => { const a: Keys = ["a"]; // @ts-expect-error const b: Keys = ["b"]; // @ts-expect-error const c: Keys = ["b", "c"]; const d: Keys = ["b", "c", "d"]; const e: Keys = ["b", "c", "e"]; const f: Keys = ["f"]; }); it("check key path string", () => { const a: StringKeys = "a"; // @ts-expect-error const b: StringKeys = "b"; // @ts-expect-error const c: StringKeys = "b.c"; const d: StringKeys = "b.c.d"; const e: StringKeys = "b.c.e"; const f: StringKeys = "f"; }); it("gets type back from string key", () => { const a: GetValueFromKeyPathString = true; const d: GetValueFromKeyPathString = true; const e: GetValueFromKeyPathString = "hello"; // @ts-expect-error const f: GetValueFromKeyPathString = "hello"; // @ts-expect-error type Z = GetValueFromKeyPathString; }); it("useFlag", () => { const { useFlag } = createFlags(); function App() { const a: boolean = useFlag("a", false); const aa: boolean = useFlag(["a"], false); // @ts-expect-error useFlag(["a"], "haha"); // @ts-expect-error useFlag("b"); // @ts-expect-error useFlag(["b"]); // @ts-expect-error useFlag(["b", "c"]); // @ts-expect-error useFlag(["b", "c"]); // @ts-expect-error useFlag(["b", "c", "e"], true); const e: string = useFlag("b.c.e", "haha"); useFlag("f", 123); return null; } }); it("Flag", () => { const { Flag } = createFlags();
{a === true}
} />; // @ts-expect-error
{a === "1"}
} />; // @ts-expect-error
{a === "1"}
} />; // @ts-expect-error null} />; // @ts-expect-error null} />; // @ts-expect-error null} />;
{d === "haha"}
} />; // @ts-expect-error
{d === true}
} />; // @ts-expect-error
{d === "true"}
} />; });