Type safety
Reflag offers type safety which reduces errors and frustation
Type safety in Reflag ensures that flag key typos become build errors. This guarantees that if you try to use a non-existent flag key, you'll receive a type error, preventing potential runtime errors and improving code reliability. For remote config, it also ensures that the shape of the payload defined on Reflag matches what your code expects.
Use the Reflag CLI to generate flag types from their definition in Reflag. Once flag types have been generated they are automatically picked up by TypeScript.
It's recommended that you do not check in the flag types, but instead generate them in your build process and on your local development machines.
Set up type safety for flags
Install the Reflag CLI and set up your repository
npm install --save-dev @reflag/cli npx reflag init
Generate the types locally
npx reflag types generate
Add the generated files to
.gitignore
echo "gen/flags.d.ts" >> .gitignore
Retrieve an API Key for your build system
Set up your build system to run the Reflag CLI to generate types (use the
--api-key
option or specify the API key in theREFLAG_API_KEY
environment variable)npx reflag apps list --api-key $REFLAG_API_KEY
Example CI workflow:
# GitHub Actions example
- name: Generate types
run: npx reflag flags types --api-key ${{ secrets.REFLAG_API_KEY }}
# GitHub Actions example (using environment):
- name: Generate types (environment)
run: npx reflag flags types
env:
REFLAG_API_KEY: ${{ secrets.REFLAG_CI_API_KEY }}
There's further guidance and examples of using Reflag CLI in CI/CD pipelines.
Last updated
Was this helpful?