Skip to content

Conversation

Copy link

Copilot AI commented Jan 6, 2026

The existing documentation stated "Use satisfies to preserve types!" without explaining what literal types are or why this matters for PageObjectModel usage.

Changes

  • Expanded JSDoc @remarks section in types/page-object.d.ts for PageObjectModel interface
    • Defined literal types with concrete examples ("#searchBar" vs string)
    • Explained type widening behavior when using : PageObjectModel annotation
    • Documented three benefits of satisfies: validation, literal type preservation, better inference
    • Added side-by-side comparison showing type differences

Example

// ❌ BAD: Type annotation widens to index signature
const page1: PageObjectModel = {
  elements: { searchBar: "#search" }  // Type: { [key: string]: string | ElementProperties }
};

// ✅ GOOD: satisfies preserves exact structure
const page2 = {
  elements: { searchBar: "#search" }  // Type: { searchBar: "#search" }
} satisfies PageObjectModel;

This enables TypeScript to know exact element keys like searchBar instead of treating elements as an arbitrary string-keyed record, improving autocomplete and type safety when using EnhancedPageObject.

Original prompt

In the above page object definition, notice that we've defined it as const myPage = {} satisfies PageObjectModel instead of const myPage: PageObjectModel = {}. Doing so helps preserve the literal type of the page object and all its components when they are passed to ElementPageObject, instead of downleveling them to take the loose types defined in PageObjectModel.

what do you mean by literal type fo the page object and all it's componentn


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Explain literal types for page objects and components Clarify literal type preservation in PageObjectModel documentation Jan 6, 2026
Copilot AI requested a review from shubhamkd January 6, 2026 08:41
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