Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Dependencies Array shows missing dependency error for generic type parameters #19808

Closed
mrousavy opened this issue Sep 10, 2020 · 4 comments

Comments

@mrousavy
Copy link

React version: 16.13.1

Steps To Reproduce

  1. Create function with generic type parameter
  2. Use that generic type parameter in useCallback, useEffect or useMemo

Example:

export function useDocument<TDocument>(path: string, defaultValue: TDocument | undefined = undefined): TDocument | undefined {
	const [value, setValue] = useState<TDocument | undefined>(defaultValue);

	const onNext = useCallback((snapshot: FirebaseFirestoreTypes.DocumentSnapshot<FirebaseFirestoreTypes.DocumentData>) => {
		if (snapshot.exists) setValue(build<TDocument>(snapshot.data(), snapshot.id));
		else setValue(undefined);
	}, []);


	useEffect(() => firestore().doc(path).onSnapshot(onNext), [onNext, path]);

	return value;
}

Screenshot 2020-09-10 at 19 57 06

The current behavior

Shows error React Hook useCallback has a missing dependency: 'TDocument'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps)

The expected behavior

Should not show any errors, because it isn't possible to add types to the dependencies array (types don't exist at runtime!)

@mrousavy mrousavy added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 10, 2020
@dsgkirkby
Copy link

I'm also seeing this issue. It only happens after updating typescript-eslint from v3.8 to v4.1.

@mrousavy
Copy link
Author

@dsgkirkby yep, might be a typescript 4.0 problem

@eps1lon
Copy link
Collaborator

eps1lon commented Sep 10, 2020

Duplicate of #19742. It should be fixed by #19751. We'll just need to wait for a release.

@eps1lon eps1lon closed this as completed Sep 10, 2020
@eps1lon eps1lon added Resolution: Duplicate and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Sep 10, 2020
@gaearon
Copy link
Collaborator

gaearon commented Sep 10, 2020

eslint-plugin-react-hooks@4.1.1 should have the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants