Re:Why Do React Hooks Rely on Call Order?
by WorldMaker on Friday December 14, 2018 @12:37PM
(#18682685)
Yeah, macros/DSLs might be a bridge too far for a lot of users.
I keep trying to figure out if there is a way to push it into a type safety problem in Typescript, at least. A compile error would be preferable to a lint error, even if not everyone uses a typing compiler like Typescript.
If there were some way that you could get use* functions to narrow to `never` in any branch or branch-like position, that would be cool. Unfortunately, I can't think of a natural way in the type system to do that that would work in even a plurality of cases. Which drops back to it needing to be a context-sensitive linter rule.
Re:Why Do React Hooks Rely on Call Order?
by politician on Friday December 14, 2018 @01:41PM
(#18683325)
You might be able to use ES6 annotations to mark use* functions such that a bespoke Babel plugin can assert that the the control flow AST only contains functions so annotated in non-branching positions.
Basically, lint, but at transpile time.
Re:Why Do React Hooks Rely on Call Order?
by WorldMaker on Friday December 14, 2018 @07:18PM
(#18686117)
Similarly, tslint operates best as a Typescript plugin and so lint rules in Typescript still can happen at transpile time and aren't necessarily that much different in practice from compiler errors. Still bugs me a little that there's not a higher-kinded type or pattern that I can come up with to do it "for real" in the compilation.
The best I can come up with is Sweet.js (hygenic macros), but can you imagine what outrage that would provoke?