Skip to content

Conversation

@Yeom-JinHo
Copy link
Contributor

Closed #1508

Description

This PR updates the isFinite utility to behave as a proper TypeScript type predicate.
Previously, it only returned a boolean value, which did not narrow the input type.
Now it returns value is number, aligning with its intended behavior and enabling type narrowing for conditional checks.


Changes

  • Type Predicate Update (major fix):
    Updated the return type from booleanvalue is number.
    This allows TypeScript to narrow the argument type to number when the function returns true.

  • Parameter Type Refinement:
    Changed the parameter type from anyunknown for safer and stricter type inference.

  • Documentation Update:
    Modified MDX docs:

    • Updated Parameters and Returns to reflect the new type predicate signature.
    • Added a TypeScript note explaining type narrowing behavior with examples.
  • Type Test Update:
    Added a dedicated type predicate test case verifying that the value is narrowed to number inside conditional blocks.


Motivation

The previous implementation’s JSDoc implied that isFinite could act as a type guard,
but it actually returned a plain boolean and didn’t affect type inference in TypeScript.
This update ensures the function truly works as a type predicate,
improving developer experience and aligning runtime behavior with TypeScript semantics.


Breaking Changes

  • No runtime behavior changes.
  • Type-level change:
    Projects relying on an explicit boolean return type may need to adjust dependent type definitions or mocks.

@Yeom-JinHo Yeom-JinHo requested a review from raon0211 as a code owner November 8, 2025 00:42
Copilot AI review requested due to automatic review settings November 8, 2025 00:42
@Yeom-JinHo Yeom-JinHo requested a review from dayongkr as a code owner November 8, 2025 00:42
@vercel
Copy link

vercel bot commented Nov 8, 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 Nov 13, 2025 9:58am

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 the isFinite function to act as a TypeScript type guard, improving type safety and developer experience. The function now properly narrows the type of unknown values to number when they are finite.

  • Updated function signature to use value is number type predicate instead of returning boolean
  • Enhanced implementation to explicitly check typeof value === 'number' before calling Number.isFinite()
  • Updated documentation across multiple languages to explain the type guard behavior

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/compat/predicate/isFinite.ts Changed return type to value is number and added explicit typeof check to properly guard against non-number types
src/compat/predicate/isFinite.spec.ts Replaced strict type equality test with compatibility test and added new test for type predicate functionality
docs/reference/compat/predicate/isFinite.md Updated return type documentation and added TypeScript type predicate explanation
docs/zh_hans/reference/compat/predicate/isFinite.md Updated return type documentation and added TypeScript type predicate explanation (Chinese)
docs/ko/reference/compat/predicate/isFinite.md Updated return type documentation and added TypeScript type predicate explanation (Korean)
docs/ja/reference/compat/predicate/isFinite.md Updated return type documentation and added TypeScript type predicate explanation (Japanese)
Comments suppressed due to low confidence (1)

docs/reference/compat/predicate/isFinite.md:49

  • The parameter type in the documentation shows any but the actual function signature uses unknown. This should be updated to unknown to match the implementation.
- `value` (`any`): The value to check.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

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

Thanks so much!

@raon0211 raon0211 merged commit 8beb7a3 into toss:main Nov 13, 2025
5 of 10 checks passed
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (175c8f5) to head (49d55db).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1511   +/-   ##
=======================================
  Coverage   99.97%   99.97%           
=======================================
  Files         468      468           
  Lines        4459     4459           
  Branches     1313     1313           
=======================================
  Hits         4458     4458           
  Misses          1        1           
🚀 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.

compat/isSafeInteger doesn't actually narrow the type

3 participants