Skip to content

Simplify types, address bugs, and improve type safety#3

Merged
J0m1ty merged 2 commits intomainfrom
dev-next
Jun 2, 2025
Merged

Simplify types, address bugs, and improve type safety#3
J0m1ty merged 2 commits intomainfrom
dev-next

Conversation

@J0m1ty
Copy link
Copy Markdown
Owner

@J0m1ty J0m1ty commented Jun 2, 2025

Changes:

  • Reduces complexity and number of utility types
  • Adds an optional type parameter to DiscriminatedUnion for type checking
  • Fixes an unknown bug

Closes #1 and closes #2

@J0m1ty J0m1ty requested a review from Copilot June 2, 2025 21:32
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

A refactor to simplify and consolidate TypeScript utility types for discriminated unions and merged unions, improving type safety and addressing a bug.

  • Replaced multiple internal helpers with UnionKeys, BuildMember, and Expand
  • Updated DiscriminatedUnion signature to include an optional Tags parameter
  • Simplified MergedUnion implementation and removed legacy merge utilities
Comments suppressed due to low confidence (3)

src/index.ts:36

  • The JSDoc template tags (@template TDiscriminator and @template TStates) no longer match the updated generic parameters (Discriminator, Variants, Tags). Please update or add @template annotations to reflect Discriminator, Variants, and the optional Tags parameter.
* @template TDiscriminator - The string literal type that will be used as the discriminator property name

src/index.ts:78

  • [nitpick] The type parameters A and B in MergedUnion<A, B> are not very descriptive. Consider renaming them to something like Left, Right or TFirst, TSecond to clarify their roles.
export type MergedUnion<

src/index.ts:78

  • This new MergedUnion logic introduces complex conditional and mapped types; consider adding dedicated type-level tests (e.g., via tsd) to verify all merge scenarios and edge cases.
export type MergedUnion<

@J0m1ty
Copy link
Copy Markdown
Owner Author

J0m1ty commented Jun 2, 2025

We should add another testing library to check actual types
https://github.com/tsdjs/tsd

@J0m1ty J0m1ty merged commit 3b571e3 into main Jun 2, 2025
2 checks passed
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.

Add optional tag validation to DiscriminatedUnion Breaks with large type & overlapping properties

2 participants