Skip to content

feat(type-plus): add .$Fn to every one-input predicate - #704

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

unional merged 1 commit into
mainfrom
feat-predicate-fn

Conversation

@unional

@unional unional commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Part 2 of #701. Part 1 (the ArrayPlus.Filter bug) is in #703. Part 3 (the two-input predicates) is waiting on a decision about parameter order.

Changes

  • Added .$Fn<$O> to all 62 one-input predicates listed in feat(type-plus): complete type-function ($Fn) support across predicates and ArrayPlus.Filter #701. It has the same shape as IsObject.$Fn: readonly out: IsX<this['in'], $O>, with $O checked by $StrictOptions.
    • The list covers the special-type, primitive, numeric and structure predicates, HasNull, HasUndefined, HasVoid, and every IsNot… counterpart, including IsNotObject.
    • IsNotX.$Fn wraps IsNotX directly, which is already the cheap inverse. It does not go through $Fn.Not.
  • Each .$Fn has a TSDoc $Fn.Apply example. The example is pinned in the predicate's existing spec, under a describe('X.$Fn') block.
  • Updated guides/type-functions.mdx: the predicate list, two examples (checked against the compiler), and a cost note on IsNot… vs $Fn.Not.
  • scripts/bench-instantiations.mjs: collection() now takes extra imports, and there are new Filter benches.
  • Added a minor changeset.

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+IsNotObject.$Fn 963.0 963.5
Filter+Not<IsObject.$Fn> 1079.6 1079.7
Filter+IsString.$Fn 952.9 953.5
Filter+IsNotString.$Fn 972.2 972.7
Filter+Not<IsString.$Fn> 1088.9 1089.5
Filter+IsInteger.$Fn 2210.1 2213.0
Filter+IsUnion.$Fn 877.5 878.0
Filter+HasNull.$Fn 1315.0 1316.3

An IsNot… counterpart saves about 110 instantiations per call (about 10%) compared with $Fn.Not.

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

Each special-type, primitive, numeric and structure predicate, the Has*
union predicates, and every IsNot* counterpart (including IsNotObject)
now exposes `.$Fn<$O>`, the same shape as `IsObject.$Fn`, with a pinned
`$Fn.Apply` example in its spec. The bench gains Filter runs for a few
of them and for `IsNotX.$Fn` against `$Fn.Not<IsX.$Fn>`.

Refs #701

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

changeset-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf966e7

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 17, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #704   +/-   ##
=========================================
  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
@unional
unional removed this pull request from the merge queue due to a manual request Sep 18, 2026
@unional
unional added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit ab2f472 Sep 18, 2026
7 checks passed
@unional
unional deleted the feat-predicate-fn branch September 18, 2026 07:22
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