Skip to content

Comments

fix(types): fix normalizeAbsent.test.tsx type errors#520

Merged
jdhoffa merged 1 commit intomainfrom
fix-ts_errors_normalize_absent
Nov 6, 2025
Merged

fix(types): fix normalizeAbsent.test.tsx type errors#520
jdhoffa merged 1 commit intomainfrom
fix-ts_errors_normalize_absent

Conversation

@jdhoffa
Copy link
Collaborator

@jdhoffa jdhoffa commented Nov 5, 2025

  • Add undefined to union types in MockObject type definition
  • Add array bounds check in normalizeList test
  • Remove unnecessary @ts-expect-error directive

Relates to #514

update MockObject to handle undefined values
Copilot AI review requested due to automatic review settings November 5, 2025 13:51
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Expected version change and release notes:

1.5.0-dev.19 (v1.5.0-dev.18...fix-ts_errors_normalize_absent ) (2025-11-05T13:53 UTC)

Fixes

  • types: fix normalizeAbsent.test.tsx type errors (f53589d)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the normalizeAbsent test suite to improve TypeScript type safety and add runtime array validation. The changes include explicit undefined in union types for optional fields, removal of a ts-expect-error suppression, and addition of a runtime check for array bounds.

  • Explicitly added | undefined to optional field type definitions in MockObject
  • Removed @ts-expect-error comment that was suppressing type errors for non-normalized fields
  • Added runtime validation to ensure array has expected elements before accessing them

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +13
temperature?: string | null | undefined;
targetYear?: number | null | undefined;
targetType?: "absolute" | "intensity" | null | undefined;
abool?: boolean | null | undefined;
zero?: number | null | undefined;
empty?: string | null | undefined;
missing?: string | undefined;
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

[nitpick] Adding | undefined to optional properties is redundant in TypeScript. The ? operator already includes undefined in the type union. For consistency and conciseness, consider removing the explicit | undefined from all optional property declarations (lines 7-13).

Suggested change
temperature?: string | null | undefined;
targetYear?: number | null | undefined;
targetType?: "absolute" | "intensity" | null | undefined;
abool?: boolean | null | undefined;
zero?: number | null | undefined;
empty?: string | null | undefined;
missing?: string | undefined;
temperature?: string | null;
targetYear?: number | null;
targetType?: "absolute" | "intensity" | null;
abool?: boolean | null;
zero?: number | null;
empty?: string | null;
missing?: string;

Copilot uses AI. Check for mistakes.
{ name: "C" }, // missing
];
const out = normalizeList(list, ["temperature"] as const);
if (!out[0] || !out[1] || !out[2])
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

The runtime check uses truthiness evaluation (!out[0]) which would fail if the array element exists but has a falsy value (e.g., an object with only falsy properties). Consider using out.length !== 3 instead to check only the array length: if (out.length !== 3) throw new Error('Expected array to have 3 items');

Suggested change
if (!out[0] || !out[1] || !out[2])
if (out.length !== 3)

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Azure Static Web Apps: Your stage site is ready! Visit it here: https://proud-glacier-0f640931e-520.westus2.2.azurestaticapps.net

@jdhoffa jdhoffa requested a review from AlexAxthelm November 5, 2025 14:25
Copy link
Collaborator

@AlexAxthelm AlexAxthelm left a comment

Choose a reason for hiding this comment

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

Noting that for other tests, I would probably cast MockObject as an actual type, but in this case, since we're testing a generic util, looks good.

@jdhoffa jdhoffa merged commit 9011576 into main Nov 6, 2025
16 checks passed
@jdhoffa jdhoffa deleted the fix-ts_errors_normalize_absent branch November 6, 2025 10:05
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