Skip to content

feat(types): support pre-typed APIs via signInteractionTrace.withTypes()#11

Merged
frankieyan merged 3 commits into
mainfrom
frankieyan/core-implementation-v3
Feb 4, 2026
Merged

feat(types): support pre-typed APIs via signInteractionTrace.withTypes()#11
frankieyan merged 3 commits into
mainfrom
frankieyan/core-implementation-v3

Conversation

@frankieyan

@frankieyan frankieyan commented Feb 3, 2026

Copy link
Copy Markdown
Member

This PR adds compile-time type safety for trace names and their associated details, inspired by Reselect's withTypes pattern. This allows consumers to define their valid traces upfront and get autocomplete + error checking throughout their codebase.

Stacked on top of #8

Example

// Define your traces once
type MyTraces = {
    'open modal': { modalId: string }
    'close modal': { modalId: string }
    'submit form': { formId: string; success: boolean }
}

// Create a pre-typed sign function (recommended)
const signTrace = signInteractionTrace.withTypes<MyTraces>()

// Use throughout your app with full autocomplete
signTrace('open modal', { modalId: 'settings' })   // ✅ autocomplete works!
signTrace('opne modal', { modalId: 'settings' })   // ❌ Error: typo caught
signTrace('open modal', { formId: 'wrong' })       // ❌ Error: wrong details shape
signTrace('submit form', { formId: 'login' })      // ❌ Error: missing 'success'

// Alternative: inline type parameter (for occasional use)
signInteractionTrace<MyTraces>('open modal', { modalId: 'settings' })

// Legacy usage still works (no type checking)
signInteractionTrace('any trace name', { anyKey: 'anyValue' })

Test plan

To verify the type safety works:

  1. Create a custom trace definitions type:

    type MyTraces = {
        'test trace': { id: string }
    }
  2. Create a pre-typed function:

    const signTrace = signInteractionTrace.withTypes<MyTraces>()
  3. Verify TypeScript catches errors:

    • Invalid trace names (e.g., signTrace('typo trace', ...))
    • Wrong payload shapes (e.g., signTrace('test trace', { wrong: 123 }))
    • Missing required properties
  4. Verify autocomplete:

    • Suggests 'test trace' when typing the first argument

@frankieyan frankieyan requested a review from a team as a code owner February 3, 2026 02:47
@frankieyan frankieyan requested review from rfgamaral and removed request for a team February 3, 2026 02:47

@doistbot-app doistbot-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a great addition, introducing a withTypes method to provide compile-time type safety for interaction traces. The implementation is clean and will certainly improve correctness for consumers. There appear to be a couple of type-level considerations, one that may prevent the API from checking as intended and another related to the effectiveness of a test case.

Base automatically changed from frankieyan/core-implementation to main February 4, 2026 02:06
frankieyan and others added 3 commits February 3, 2026 18:07
This PR adds compile-time type safety for trace names and their associated
details, inspired by Reselect's `withTypes` pattern. This allows consumers
to define their valid traces upfront and get autocomplete + error checking
throughout their codebase.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@frankieyan frankieyan force-pushed the frankieyan/core-implementation-v3 branch from c43d3ef to 4dc5271 Compare February 4, 2026 02:09
@frankieyan frankieyan merged commit c191fe0 into main Feb 4, 2026
2 checks passed
@frankieyan frankieyan deleted the frankieyan/core-implementation-v3 branch February 4, 2026 02:10
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