Skip to content

Fix TypeScript error in useQueryBuilder test#31

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-ci-build-and-test
Feb 10, 2026
Merged

Fix TypeScript error in useQueryBuilder test#31
hotlong merged 3 commits intomainfrom
copilot/fix-ci-build-and-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 10, 2026

CI failing on tsc --noEmit due to accessing property on unknown type.

serializeFilterTree() returns unknown | null per ObjectQL spec (supports multiple array shapes). Test mock returns structured object but TypeScript doesn't know this.

Changes

  • Add SerializedFilter interface matching mock return type
  • Use typed assertion: (serialized as SerializedFilter).logic
interface SerializedFilter {
  logic: string;
  filters: Array<{
    field: string;
    operator: string;
    value: string;
  }>;
}

// In test:
expect((serialized as SerializedFilter).logic).toBe("AND");
Original prompt

引用: https://github.com/objectstack-ai/mobile/actions/runs/21832572220/job/62994778979#step:6:1

fix all ci build and test


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 10, 2026 00:36
Add type assertion for serialized filter result to fix TS18046 error where 'serialized' was of type 'unknown'.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Define SerializedFilter interface for better type safety when testing the serialize() method.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix all CI build and test issues Fix TypeScript error in useQueryBuilder test Feb 10, 2026
Copilot AI requested a review from hotlong February 10, 2026 00:40
@hotlong hotlong marked this pull request as ready for review February 10, 2026 00:47
Copilot AI review requested due to automatic review settings February 10, 2026 00:47
@hotlong hotlong merged commit 14fb6a3 into main Feb 10, 2026
Copy link
Copy Markdown

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 addresses a TypeScript compile error in the useQueryBuilder hook test by introducing a local type for the mocked serialize() output and casting the unknown return value to access logic.

Changes:

  • Add a SerializedFilter interface in the test file to describe the mocked serialized shape.
  • Update the serialization assertion to use a type assertion when accessing logic.

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

Comment on lines 197 to +199
const serialized = result.current.serialize();
expect(serialized).toBeDefined();
expect(serialized.logic).toBe("AND");
expect((serialized as SerializedFilter).logic).toBe("AND");
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

expect(serialized).toBeDefined() doesn’t exclude null (null is “defined”), so if serialize() ever returns null this test will throw when accessing .logic rather than failing with a clear assertion. Prefer asserting non-null (e.g., not.toBeNull() / not.toBeNull() + type guard) or use an objectContaining({ logic: "AND" }) matcher to avoid unsafe property access on unknown.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +15
/* ---- Types ---- */
interface SerializedFilter {
logic: string;
filters: Array<{
field: string;
operator: string;
value: string;
}>;
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The new SerializedFilter interface suggests the real ObjectQL serialization format is an object with logic/filters, but the production serializeFilterTree() returns an array-based AST (unknown | null). To avoid confusion, consider renaming this to something test/mock-specific (e.g., MockSerializedFilter) or switching the expectation to structural matching without introducing a misleading type name.

Copilot uses AI. Check for mistakes.
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.

3 participants