-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Closed
Description
- I tried using the
@types/xxxxpackage and had problems. - I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
- I understand that
@typespackage versions do not follow SemVer. - I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
- Mention the authors (see
Definitions by:inindex.d.ts) so they can respond.- Authors: @Jessidhia
// 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);tim-mukhin, janziemba, kryops and DianomiJH
Metadata
Metadata
Assignees
Labels
No labels