You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A bit of a tangent on the discussion of #89 and #90: I'm not sure how useful AnyFunc is as a whole, nowadays.
I'm skimming through our codebase, and all of the usages of AnyFunc I see are either somewhat wrong, or else looser than they should be - (due to better tuple type support). The two big categories I'm seeing are:
AnyFunc<T> where () => T would be more appropriate, (or AnyFunc where () => void would be more appropriate)
I think the cases where you really don't care what the arguments to a function are is a pretty small niche.
We don't have to remove or deprecate it just because it's niche, but I do think there's a potential source of confusion in having a type that looks more useful than it actually is in practice.
The text was updated successfully, but these errors were encountered:
Perhaps AnyFunc could be replaced with some more fine-grained function types? More things like Predicate<T>
Looking at java.util.function as inspiration, (When you're looking for nouns, no language has nouns like Java) they've got stuff like:
// UsefultypeSupplier<T>=()=>T;typeConsumer<T>=(t: T)=>void;typeUnaryOperator<T>=(t: T)=>T;// Somewhat less usefultypeFunc<T,R>=(t: T)=>R;// Cound make an arbitrary arity version of this, tootypeBiConsumer<T,U>=(t: T,u: U)=>void;typeBiPredicate<T,U>=(t: T,u: U)=>boolean;typeBiFunc<T,U,R>=(t: T,u: U)=>R;// Everything else seems to be stuff like this, which seems excessive:typeIntConsumer=Consumer<number>
The top three especially seem worth having. (And the Java names are pretty reasonable, IMO, though maybe there are better ones) Supplier<T> would replace a lot of our current usages of AnyFunc<T>.
As for the other major use-case for AnyFunc I've see, wrapping functions, I'm not sure there's any sort of type that can make that easier. I tried a type Wrap<F extends Function> = (f: F) => F, but I can't find a way to make that useful without just needing a ugly cast anyway.
A bit of a tangent on the discussion of #89 and #90: I'm not sure how useful
AnyFunc
is as a whole, nowadays.I'm skimming through our codebase, and all of the usages of
AnyFunc
I see are either somewhat wrong, or else looser than they should be - (due to better tuple type support). The two big categories I'm seeing are:AnyFunc<T>
where() => T
would be more appropriate, (orAnyFunc
where() => void
would be more appropriate)For example:
This is a bit dangerous, because:
AnyFunc
that unnecessarily return(...args: any[])
where a more specific set of arguments would be appropriate:This is better as something like:
I think the cases where you really don't care what the arguments to a function are is a pretty small niche.
We don't have to remove or deprecate it just because it's niche, but I do think there's a potential source of confusion in having a type that looks more useful than it actually is in practice.
The text was updated successfully, but these errors were encountered: