es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

isFunction: difference with lodash

Open rejetto opened this issue 11 months ago • 4 comments

hi, isFunction in lodash is also working as "type guard", meaning that typescript knows that inside an if(isFunction(f)) then "f" is a function. This is not happening with 'es-toolkit/compat'.

I'm going to just replace it with typeof f === 'function', but you may want to consider it to get 100% compatibility.

rejetto avatar Feb 01 '25 11:02 rejetto

Type guard works in my code, can you give your code please?

gs18004 avatar Feb 02 '25 09:02 gs18004

i must specify that i'm using typescript 4.9.5

import {  MutableRefObject } from 'react'

type FunctionRef<T=HTMLElement> = (instance: (T | null)) => void
export function passRef<T=any>(el: T, ...refs: (MutableRefObject<T> | FunctionRef<T>)[]) {
    for (const ref of refs)
        if (_.isFunction(ref))
            ref(el)
        else if (ref)
            ref.current = el
}

when i switch to es-toolkit, i get a typescript error on the "ref.current" line, saying it can be a function and thus doesn't have "current"

rejetto avatar Feb 02 '25 10:02 rejetto

+1

l246804 avatar Mar 20 '25 10:03 l246804

Is there any plan to fix it?

l246804 avatar May 09 '25 07:05 l246804

This is fixed in the latest version of our library.

raon0211 avatar Nov 13 '25 09:11 raon0211