Skip to content

feat(core): allow omitting context in initial state for optional context types - #181

Merged
Junnis0123 merged 1 commit into
mainfrom
feat/optional-initial-context
Mar 3, 2026
Merged

feat(core): allow omitting context in initial state for optional context types#181
Junnis0123 merged 1 commit into
mainfrom
feat/optional-initial-context

Conversation

@Junnis0123

Copy link
Copy Markdown
Collaborator

Summary

  • Allow omitting context in useFunnel's initial option when all context properties are optional
  • Default TContext to {} in createFunnelSteps()

Changes

@use-funnel/core

  • Add FunnelInitialStateByContextMap type (core.ts)

    • Makes context optional when Partial<TContext> extends TContext
    • context remains required when the type has any required properties
  • Introduce normalizedInitial (useFunnel.tsx)

    • Normalizes with context ?? {} before passing to router adapters
    • Behavior is identical to the existing code when context is always provided
  • Add default type parameter to createFunnelSteps (stepBuilder.ts)

    • createFunnelSteps<TContext>()createFunnelSteps<TContext = {}>()

Example

// Before: context was always required even if all properties are optional
useFunnel<{ A: { foo?: string }; B: {} }>({
  id: 'test',
  initial: { step: 'A', context: {} },
});

// After: context can be omitted when all properties are optional
useFunnel<{ A: { foo?: string }; B: {} }>({
  id: 'test',
  initial: { step: 'A' },
});

@Junnis0123 Junnis0123 self-assigned this Mar 3, 2026
@Junnis0123
Junnis0123 merged commit 8efd2d4 into main Mar 3, 2026
1 of 2 checks passed
@Junnis0123
Junnis0123 deleted the feat/optional-initial-context branch March 3, 2026 03:42
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.

1 participant