roact-rodux icon indicating copy to clipboard operation
roact-rodux copied to clipboard

Add types for dispatch prop

Open jkelaty-rbx opened this issue 3 years ago • 5 comments
trafficstars

This PR adds types for the dispatch prop. This includes a standard action dispatch and a thunkful action dispatch variant.

Inspired by: https://github.com/reduxjs/react-redux/blob/master/src/types.ts

This RP also adds typechecking to CI with luau-lsp.

jkelaty-rbx avatar Aug 09 '22 01:08 jkelaty-rbx

Coverage Status

Coverage decreased (-67.9%) to 32.09% when pulling 85fcd6690ac2ddb7f0c1cd859d38b53cd29cddd8 on jkelaty-rbx:action-thunk-prop-types into d7ef4d823a28503a13dcfe1f15c0f48b6dd6cee4 on Roblox:master.

coveralls avatar Aug 16 '22 00:08 coveralls

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

github-actions[bot] avatar Aug 16 '22 00:08 github-actions[bot]

I think this mostly looks good, but I can see that one of your previous analysis "failures" still got marked as green: image Can we introduce an analyze error in a commit, validate that CI fails, and the revert it before merge? I've had odd behaviors with tools exiting with an error and still passing CI steps, so I'm perhaps a bit paranoid 😅

Yeah, I'm guessing (likely mistakingly) luau-lsp doesn't factor a missing directory for its exit code. My test commit successfully failed CI, so we should be good!

jkelaty-rbx avatar Aug 16 '22 04:08 jkelaty-rbx

@ZoteTheMighty Thanks for the quick review! Feel free to merge whenever

jkelaty-rbx avatar Aug 16 '22 04:08 jkelaty-rbx

Looking good, but I'm curious: Are these types enough to catch bugs?

@matthargett This is a great question. These types might catch bugs where we try to pass something other than an action or a thunk into dispatch, but their main utility is unfortunately to work around some of Luau's constraints. The issue that I ran into was when I was dispatching non-homogenous types within the same dispatch scope. Luau would try to narrow the dispatch arg on the first invocation and then complain about subsequent calls, thus type checking fails.

However, I just did some quick testing to verify what I said, and I stumbled onto another issue with void returning thunks that I will need to follow up on, so we should put this PR on pause until then anyway.

jkelaty-rbx avatar Aug 16 '22 17:08 jkelaty-rbx