Skip to content

Conversation

@wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Oct 11, 2025

Summary

This PR improves the once function by removing the type assertion (as F) and using an explicit return type instead. This change enhances type safety while maintaining the same functionality.

Changes

  • Removed as F type assertion from the return statement
  • Changed return type from F to (...args: Parameters<F>) => ReturnType<F>
  • Simplified the first function overload to match the implementation signature
  • Improved type safety by letting TypeScript properly infer and validate the return type

Copilot AI review requested due to automatic review settings October 11, 2025 14:45
@vercel
Copy link

vercel bot commented Oct 11, 2025

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

Project Deployment Preview Comments Updated (UTC)
es-toolkit Ready Ready Preview Comment Oct 11, 2025 2:50pm

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances type safety in the once function by removing a type assertion and replacing it with an explicit return type. The change eliminates the unsafe as F cast while maintaining the same functionality through proper TypeScript type inference.

Key Changes

  • Removed the as F type assertion from the return statement
  • Changed the return type from F to (...args: Parameters<F>) => ReturnType<F>
  • Reformatted the function signature for better readability
Comments suppressed due to low confidence (1)

src/function/once.ts:15

  • The first overload signature should be updated to match the new implementation return type (...args: Parameters<F>) => ReturnType<F> for consistency.
export function once<F extends (...args: any[]) => any>(func: F): F;

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.90%. Comparing base (21bd853) to head (75f5f42).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1462   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files         468      468           
  Lines        4439     4439           
  Branches     1309     1309           
=======================================
  Hits         4435     4435           
  Misses          4        4           
🚀 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.

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