Skip to content

fix: accept IFlagsmithTrait in identify() traits, matching setTraits() - #421

Merged
Zaimwa9 merged 1 commit into
Flagsmith:mainfrom
chiliec:fix/identify-trait-type
Sep 21, 2026
Merged

Zaimwa9 merged 1 commit into
Flagsmith:mainfrom
chiliec:fix/identify-trait-type

Conversation

@chiliec

@chiliec chiliec commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

What

flagsmith.identify() was typed as traits?: Record<T, IFlagsmithValue>, so passing a TraitEvaluationContext (e.g. { value: "abc", transient: true }) was a compile error even though setTraits() accepts Record<T, IFlagsmithTrait> and the runtime identify() in flagsmith-core.ts already handles it via isTraitEvaluationContext().

Fix

Type-only change in types.d.ts: identify() traits now use IFlagsmithTrait, matching setTraits()/setTrait(). This widens the accepted type — no existing caller breaks.

Tests

Added a case to test/types.test.ts that calls both setTraits() and identify() with the same trait object containing a transient TraitEvaluationContext, plus a @ts-expect-error for an undeclared trait key so the generic T is still enforced.

Validation (Node 22.14):

  • npx tsc before the fix: test/types.test.ts(103,62): error TS2322: Type '{ value: string; transient: true; }' is not assignable to type 'string | number | boolean | null'
  • npx tsc after the fix: exit 0
  • npm test (jest --env=jsdom): 19 suites, 126 tests passed

Closes #383

@chiliec
chiliec requested a review from a team as a code owner September 19, 2026 23:38
@chiliec
chiliec requested review from talissoncosta and removed request for a team September 19, 2026 23:38

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for the contribution

@Zaimwa9
Zaimwa9 merged commit 42b0bd2 into Flagsmith:main Sep 21, 2026
2 checks passed
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.

identify() should accept IFlagsmithTrait for traits parameter (parity with setTraits)

2 participants