Skip to content

fix: Replace unsafe in-operator checks with compile-time type guards#237

Open
Who-is-PS wants to merge 1 commit intomainfrom
dev-v3-philosr-refactor-5
Open

fix: Replace unsafe in-operator checks with compile-time type guards#237
Who-is-PS wants to merge 1 commit intomainfrom
dev-v3-philosr-refactor-5

Conversation

@Who-is-PS
Copy link
Member

@Who-is-PS Who-is-PS commented Feb 27, 2026

Issue #, if available:

Description of changes:

TypeScript doesn't validate the in operator at compile time — 'banana' in obj compiles without error. This is the same class of bug that caused the COE (property filter not creating filtering tokens), where a 'prop' in obj check silently passed with an incorrect property name.

All 3 source-file usages in this repo discriminate the PropertyFilterProps.Token | PropertyFilterProps.TokenGroup union — the exact same type that caused the original bug.

Solution

Replace all raw 'prop' in obj checks with type guard functions that use keyof to validate property names at compile time. If someone typos a property name, TypeScript will now surface a compile error instead of silently allowing it.

Changes

  • New: src/common/property-filter-type-guards.ts — shared isTokenGroup() and isToken() type guards
  • Updated: src/pages/table-saved-filters/filter-set-modals.tsx — use isTokenGroup()
  • Updated: src/fake-server/distributions.ts — use isTokenGroup() and isToken()
  • Updated: test/e2e/a11y.test.ts — local isAxeError() type guard

4 checks replaced across 3 files. Zero behavioral changes.

Verification

  • No visual or behavioral changes
  • All existing tests pass

References

  • COE: Property filter not creating filtering tokens
  • SIM: AWSUI-59006
    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
  • Tech Proposal. (k9wvA3eNMiZ9).

@Who-is-PS Who-is-PS marked this pull request as ready for review March 3, 2026 16:27
@Who-is-PS Who-is-PS requested a review from a team as a code owner March 3, 2026 16:27
@Who-is-PS Who-is-PS requested review from srungta08 and removed request for a team March 3, 2026 16:27
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.

2 participants