Skip to content

Conversation

@kyle-ssg
Copy link
Member

@kyle-ssg kyle-ssg commented Mar 19, 2025

  • 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 feat: Add interface types flagsmith-cli#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

@kyle-ssg kyle-ssg requested a review from tiagoapolo March 19, 2025 17:08
@kyle-ssg kyle-ssg marked this pull request as ready for review March 19, 2025 17:08
@jhoermann
Copy link
Contributor

According to Semantic versioning features should be a minor version bump @kyle-ssg.

# Conflicts:
#	lib/flagsmith/package.json
#	lib/react-native-flagsmith/package.json
@kyle-ssg kyle-ssg merged commit fcc5f34 into main Apr 8, 2025
1 check passed
@kyle-ssg kyle-ssg deleted the feat/interface-definitions branch April 8, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants