Skip to content

fix(pipe): proper TypeScript typing with function overloads#235

Merged
AliiiBenn merged 7 commits intomainfrom
fix/pipe-type-safety
Mar 27, 2026
Merged

fix(pipe): proper TypeScript typing with function overloads#235
AliiiBenn merged 7 commits intomainfrom
fix/pipe-type-safety

Conversation

@AliiiBenn
Copy link
Copy Markdown
Member

@AliiiBenn AliiiBenn commented Mar 27, 2026

Summary

  • Add function overloads for pipe (up to 7 functions) for proper type inference
  • Add function overloads for flow where first function can accept multiple arguments
  • Replace reduce with for loop for better performance
  • Add pipeAsync — async composition with Promise unwrapping at each step
  • Add flowAsync — create reusable async composed functions
  • Add tap — execute side effects without altering the value (for logging/debugging)
  • Add tapAsync — async version of tap for analytics/tracking
  • Add comprehensive tests (23 tests for pipe module)
  • Add environment-specific tests for yield

Benefits

  1. Flawless type inference — TypeScript knows exact types at each step
  2. First-function arityflow((a, b) => a + b, n => n.toString())(5, 10) works
  3. Async supportpipeAsync/flowAsync for async composition
  4. Side effects without pollutiontap/tapAsync for logging/monitoring
  5. Performancefor loop is faster than reduce

Test plan

  • TypeScript type checking passes
  • All 489 tests pass
  • Lint passes
  • CI coverage — PRE-EXISTING ISSUE: retry.ts (87.5% branches) has coverage below 95% threshold. This is not caused by this PR.

🤖 Generated with Claude Code

- Add function overloads for pipe (up to 7 functions) for proper type inference
- Add function overloads for flow where first function can accept multiple arguments
- Replace reduce with for loop for better performance
- Update examples in JSDoc

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
core-web Ready Ready Preview, Comment Mar 27, 2026 2:57pm

Add comprehensive tests for pipe and flow functions to improve coverage.

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
Test scheduler.yield, setImmediate, and MessageChannel paths.
Verify immediate is same reference as yieldControl.

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
- Add pipeAsync for async composition with Promise unwrapping at each step
- Add flowAsync for creating reusable async composed functions
- Add tap for side effects without altering the value
- Add tapAsync for async side effects
- All new functions have proper TypeScript overloads for type inference

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
- Replace Function type with AnyFn for better type safety
- Add thenable check in pipeAsync/flowAsync to avoid unnecessary microtasks
- Add tapSafe for error-safe side effects
- Add comprehensive tests for tapSafe

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
- Add function check to isThenable for better compatibility with thenable objects
- Check initial value in pipeAsync to avoid unnecessary microtasks

Note: Kept AnyFn with unknown[] instead of any to satisfy strict lint rules.
Overloads provide public-facing type safety regardless.

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
Re-add Promise<unknown> casts that were accidentally removed during rebase.
Keeping unknown types for lint compliance.

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
@AliiiBenn AliiiBenn merged commit bd3c322 into main Mar 27, 2026
4 of 5 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.

1 participant