Skip to content

Paths: Fix behavior with WeakMaps / WeakSets#1348

Merged
sindresorhus merged 2 commits intomainfrom
refactor/paths-implementation
Feb 5, 2026
Merged

Paths: Fix behavior with WeakMaps / WeakSets#1348
sindresorhus merged 2 commits intomainfrom
refactor/paths-implementation

Conversation

@som-sm
Copy link
Collaborator

@som-sm som-sm commented Feb 5, 2026

This PR:

  1. Cleans up the implementation of Paths:

    • Removes certain unnecessary conditionals.
    • Improves the formatting a bit.
    • Improves comments
  2. Adds WeakMap and WeakSet in the exclusion list.

    type Current = Paths<{a: WeakMap<{a: string}, number>; b: WeakSet<{a: string}>}>;
    //=> "a" | "b" | "a.delete" | "a.get" | "a.has" | "a.set" | "b.delete" | "b.has" | "b.add"
    
    type Updated = Paths<{a: WeakMap<{a: string}, number>; b: WeakSet<{a: string}>}>;
    //=> "a" | "b"

This PR is basically for the cleanup, it doesn't change any logic. The WeakMap / WeakSet fix is included here because it's a pretty minor fix.

@som-sm som-sm force-pushed the refactor/paths-implementation branch from 8b1ff5b to 99c846c Compare February 5, 2026 10:43

declare const anyLeaves: Paths<{a: {b: any}}, {leavesOnly: true}>;
expectType<'a.b'>(anyLeaves);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Intentionally skipped the following test:

declare const neverLeaves: Paths<{a: {b: never}}, {leavesOnly: true}>;
expectType<'a.b'>(neverLeaves);

Because this one breaks currently, it's a simple fix, will open a separate PR for it.

@som-sm som-sm requested a review from sindresorhus February 5, 2026 10:52
Repository owner deleted a comment from claude bot Feb 5, 2026
Repository owner deleted a comment from claude bot Feb 5, 2026
Repository owner deleted a comment from claude bot Feb 5, 2026
@sindresorhus sindresorhus merged commit ac3b50e into main Feb 5, 2026
8 checks passed
@sindresorhus sindresorhus deleted the refactor/paths-implementation branch February 5, 2026 21:14
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