Skip to content

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

Merged
Who-is-PS merged 1 commit intomainfrom
dev-v3-philosr-refactor-5
Mar 10, 2026
Merged

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

Conversation

@Who-is-PS
Copy link
Copy Markdown
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
@Who-is-PS Who-is-PS added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 41c1061 Mar 10, 2026
5 checks passed
@Who-is-PS Who-is-PS deleted the dev-v3-philosr-refactor-5 branch March 10, 2026 14:25
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