// With `--noImplicitAny` set to true I expect the following code to error.
// $ExpectError
useCallback((implicitAnyHere) => '', [])
// And this one to compile
useCallback((good: string) => '', [])
// As well as this one
useCallback<(arg: string) => string>((good) => '', [])
Currently type definition for useCallback breaks the guarantees that --noImplicitAny gives. If developer does not specify a type for a function they are passing, all the arguments will default to any, which can easily lead to errors. I would argue that for the end developer/consumer this any type is implicit. It was totally unexpected for me and I discovered it by getting a runtime error which I would expect to be caught compile-time.
You can play around with it here.
Changing type definition to the following will fix the issue, however use of Function type is discouraged and comes as error when running npm test react.
function useCallback<T extends Function>(callback: T, deps: DependencyList);
@types/xxxxpackage and had problems.@typespackage versions do not follow SemVer.Definitions by:inindex.d.ts) so they can respond.Currently type definition for
useCallbackbreaks the guarantees that--noImplicitAnygives. If developer does not specify a type for a function they are passing, all the arguments will default toany, which can easily lead to errors. I would argue that for the end developer/consumer thisanytype is implicit. It was totally unexpected for me and I discovered it by getting a runtime error which I would expect to be caught compile-time.You can play around with it here.
Changing type definition to the following will fix the issue, however use of
Functiontype is discouraged and comes as error when runningnpm test react.