Skip to content

feat(type-plus): add .$Fn to the two-input predicates - #705

Merged
unional merged 1 commit into
mainfrom
feat-two-input-predicate-fn
Sep 18, 2026
Merged

unional merged 1 commit into
mainfrom
feat-two-input-predicate-fn

Conversation

@unional

@unional unional commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Part 3 of #701, the last part. Parts 1 (#703) and 2 (#704) are merged.

The parameter order follows the decision on the issue's open question: the function's input is the value being checked, and the other input is fixed as .$Fn's first type parameter, ahead of $O.

type R = TuplePlus.Filter<[1, number, 1], Equal.$Fn<1>> // [1, 1]
type R = TuplePlus.Find<[string, 1], Assignable.$Fn<number>> // 1
type R = TuplePlus.Filter<[{ a: 1 }, {}], HasKey.$Fn<'a'>> // [{ a: 1 }]

Changes

  • Added .$Fn<Fixed, $O> to Assignable, NotAssignable, Equal, HasKey and IsOptionalKey. $O is checked by $StrictOptions, as on the other .$Fns.
  • Each has a TSDoc example, pinned in that symbol's own spec.
  • Updated guides/type-functions.mdx with the shape and the reason only one of the two inputs can be the entry.
  • New Filter benches for Equal.$Fn, Assignable.$Fn and HasKey.$Fn.
  • Added a minor changeset.

No reverse-direction variant ($FnFrom), as decided. It can follow if a use case appears.

Instantiation cost

Per TuplePlus.Filter call on a distinct 10-entry tuple, 100 uses:

Type TS 6.0 TS 7
Filter+object 679.7 679.7
Filter+IsObject.$Fn 967.3 967.3
Filter+Equal.$Fn 952.2 952.9
Filter+Assignable.$Fn 1112.0 1112.7
Filter+HasKey.$Fn 857.3 858.3

Equal.$Fn<1> costs about the same as IsObject.$Fn, so an exact match is no more expensive than any other predicate function.

Verification

  • Type tests pass on all five compilers: pnpm --filter type-plus test:type.
  • test:errors matches the snapshot on all five compilers.
  • pnpm verify passes. Locally, check flagged only an untracked harness file that is not part of this PR.

🤖 Generated with Claude Code

`Assignable`, `NotAssignable`, `Equal`, `HasKey` and `IsOptionalKey` take
two inputs, and a type function has one. The entry being checked is the
function's input; the other input is fixed as `.$Fn`'s first type
parameter, ahead of the options.

Closes #701

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cbab0f0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
type-plus Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ab2f472) to head (cbab0f0).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #705   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           43        43           
  Lines          231       231           
  Branches        51        51           
=========================================
  Hits           231       231           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@unional
unional added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 26d0d66 Sep 18, 2026
7 checks passed
@unional
unional deleted the feat-two-input-predicate-fn branch September 18, 2026 08:55
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