Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace: Fix instantiations with unions #1065

Merged
merged 1 commit into from
Mar 2, 2025
Merged

Conversation

som-sm
Copy link
Collaborator

@som-sm som-sm commented Mar 1, 2025

Fixes behaviour of Replace when instantiated with unions.

  1. When Search is a union

    type Current = Replace<'bar', 'a' | 'b', 'z'>;
    //   ^? type Current = "zr" | "zar" | "bzr" | "bzar"
    
    type Updated = Replace<'bar', 'a' | 'b', 'z'>;
    //   ^? type Updated = "bzr" | "zar"
    type Current = Replace<'barbar', 'a' | 'b', 'z', {all: true}>;
    //   ^? type Current = "zrbzr" | "zrbzzr" | "zrzr" | "zrzzr" | "zzzr" | "zzrbzr" | "zzrbzzr" | "zzrzr" | "zzrzzr" | "zarzzr" | "zarzrbzr" | "zarzrbzzr" | "zarzrzr" | "zarzrzzr" | "bzrbzr" | "bzrbzzr" | ... 11 more ... | "bzarzrzzr"
    
    type Updated = Replace<'barbar', 'a' | 'b', 'z', {all: true}>;
    //   ^? type Updated = "bzrbzr" | "zarzar"
  2. When Replacement is a union

    type Current = Replace<'barbar', 'a', 'x' | 'z', {all: true}>;
    //   ^? type Current = "bxrbxr" | "bxrbzr" | "bzrbxr" | "bzrbzr"
    
    type Updated = Replace<'barbar', 'a', 'x' | 'z', {all: true}>;
    //   ^? type Updated = "bxrbxr" | "bzrbzr"

@som-sm som-sm requested a review from sindresorhus March 1, 2025 14:55
@sindresorhus sindresorhus merged commit a733698 into main Mar 2, 2025
13 checks passed
@sindresorhus sindresorhus deleted the fix/replace-with-unions branch March 2, 2025 06:39
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