Skip to content

Conversation

@andrewiggins
Copy link
Member

Improve the typing in hooks source file and add it to the jsconfig for linting on each PR.

One big change, that others may have opinions about, is that here I used unknown for types where we explicitly don't know what it is because it is user provided (e.g. the return type of the callback given to useMemo). Meaning, usages of any in hooks are places where we could improve the types, but I couldn't be bothered cuz it wasn't straightforward. Something to consider improving for later lol.

I wanted to to do this cuz I was recently looking at a compat bug in hooks and was working on a fix but refactoring things in hooks was slightly more difficult given I couldn't trust the red squiggles to be meaningful or not. After this PR they are hopefully more helpful (or at least mean you should double check this before adding an any override lol).

@coveralls
Copy link

Coverage Status

coverage: 99.464% (+0.001%) from 99.463%
when pulling b583fad on hook-src-types
into aa53ecb on main.

@github-actions
Copy link

Size Change: -26 B (0%)

Total Size: 59.6 kB

Filename Size Change
hooks/dist/hooks.js 1.52 kB -6 B (0%)
hooks/dist/hooks.module.js 1.56 kB -1 B
hooks/dist/hooks.umd.js 1.6 kB -19 B (1%)
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.98 kB 0 B
compat/dist/compat.module.js 3.9 kB 0 B
compat/dist/compat.umd.js 4.04 kB 0 B
debug/dist/debug.js 3.52 kB 0 B
debug/dist/debug.module.js 3.52 kB 0 B
debug/dist/debug.umd.js 3.6 kB 0 B
devtools/dist/devtools.js 232 B 0 B
devtools/dist/devtools.module.js 240 B 0 B
devtools/dist/devtools.umd.js 315 B 0 B
dist/preact.js 4.49 kB 0 B
dist/preact.min.js 4.53 kB 0 B
dist/preact.min.module.js 4.52 kB 0 B
dist/preact.min.umd.js 4.55 kB 0 B
dist/preact.module.js 4.51 kB 0 B
dist/preact.umd.js 4.57 kB 0 B
jsx-runtime/dist/jsxRuntime.js 963 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 938 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 1.04 kB 0 B
test-utils/dist/testUtils.js 453 B 0 B
test-utils/dist/testUtils.module.js 454 B 0 B
test-utils/dist/testUtils.umd.js 536 B 0 B

compressed-size-action

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I'm all for stronger typing. Going with unknown is the right move imo 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants