-
Notifications
You must be signed in to change notification settings - Fork 0
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
Rule idea: enforce "correct" branch() typing via type-aware rule? #58
Comments
This seems tough, because in the case of ad-hok helpers which may be built with a |
Ah good point - I guess that's sort of because of the "hoisting" magic of nested Since we're in ESLint-world, could bake in naming-convention-awareness and for ad-hok helpers either disable this rule or have it assume that it would be included in a React component in which case we're dealing with a known return type ( |
So use the presence of (specific?) ad-hok helpers as a clue that you are in React-land? That might work. I think we'd have to try it and see if in practice there were too many false positives. This feels like it is begging for a type-level solution, but it's hard to imagine one that doesn't make the ergonomics of ad-hok way worse. Like we were talking about earlier, this feels "monad-y" to me, but without the syntactic sugar that Haskell/etc. provide for you for monad operations, I think it'd feel very heavyweight. |
I'm not sure if this will be comprehensible without being familiar with Haskell, but the way something like that would look there would be: userComponent = do
user <- loadUser
let firstName = user.firstName
lastName = user.lastName
_ <- redirectIfNotAuthorized user -- return value unused, so _
h1 (firstName + " " + lastName) The lines with The syntax is basically just writing a bunch of |
No what I meant is that if we're basically starting from seeing a But ya there could likely be other clues eg in the body of the Actually another way to distinguish could be that since you basically only use In practice there are things that don't fit these patterns though, eg
But this approach is fundamentally a "patch" so might as well start with the most common cases and then refine the patching further |
I'm a couple steps away from being able to follow this
Ya it's unlikely that I'd want to change the ergonomics of ad-hok but still find it interesting to try and wrap my head around the patterns |
Ok started playing with a type-aware ESLint rule on the I've figured out how to extract what appears to be a correct return type of a |
Ok it seems clear that this is not exposed by the Typescript type checker API: microsoft/TypeScript#9879 / microsoft/TypeScript#9943. But might be worth checking out the |
As discussed with @peterstuart, it seems maybe impossible to truly correctly type
branch()
/branchPure()
/renderNothing()
/returns()
(in the context offlowMax()
's typing)But it seems feasible to enforce that eg you don't return something unexpected from a
branch()
+returns()
via a type-aware ESLint rule that eg looks for uses ofreturns()
and compares its "return type" against the calculated return type of the enclosingflowMax()
(and flags if they disagree)?The text was updated successfully, but these errors were encountered: