flagsmith-js-client
flagsmith-js-client copied to clipboard
feat: Add interface types
- Allows providing a full type definition of existing flags and typed remote configuration for: flagsmith, useFlags, useFlagsmith, hasFeature and getValue
- Supports type file generated by https://github.com/Flagsmith/flagsmith-cli/pull/24
- In order for this to be fully supported, useFlags will now attempt to silently parse JSON types
export interface FlagsmithTypes {
"4eyes": null;
a_temp_feature: number;
allow_client_traits: null;
announcement: Announcement;
}
export type export interface Announcement {
id?: string;
title?: string;
description?: string;
buttonText?: string;
url?: string;
isClosable?: boolean;
}
Example 1
import flagsmith as IFlagsmith<FlagsmithTypes> // or const flagsmith = useFlagsmith<FlagsmithTypes>()
flagsmith.getValue("announcement",{json:true}) // type: Announcement
flagsmith.getValue("fail") // fails types
flagsmith.hasFeature("announcement") // passes
flagsmith.hasFeature("fail") // fails types
Example 2
const {announcement} = useFlags<FlagsmithTypes>(["announcement"]) // announcement.value is of type Announcement
const {fail} = useFlags<FlagsmithTypes>(["fail"]) // fails types
According to Semantic versioning features should be a minor version bump @kyle-ssg.