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
declarefunctionuseCallback<Textends(...args: any[])=>any>(callback: T,): T;consttest: ((x: string)=>void)|undefined=useCallback((x)=>{x;// ❌ type is inferred as `any`, expected `string`});
For context, this typing of useCallback is extracted from the React types.
The problem here is the contextual type being undefined | (x: string) => void instead of just (x: string) => void - that defeats our matching logic for using the return type as an inference candidate for T
TypeScript Version: 4.0.2
Search Terms:
Code
For context, this typing of
useCallback
is extracted from the React types.Expected behavior: see above
Actual behavior: see above
Playground Link: https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtX2QGcQBhKCCAIyjAGsAeAFXhAA8MRVhD4AKAOkGwA5oQBc8KKgCeAbQC6ASngBeAHySZa3gCh4++GHJUatCYwA0OxeYDcOsHkIZ4HZxN69WE5zCyphZXV4ADccLGBlAB8CLhBEfxBgVQJiMgpqOk9WII0Abz0DVlt4AHpS+EAZcldpAAcELB5-RBAYOGSoHgADKWkuixZWeswk+C7ff2EunQBfRVsgA
Related Issues:
The text was updated successfully, but these errors were encountered: