Dwinship/typescript/coder and decoder annotations#13
Dwinship/typescript/coder and decoder annotations#13Cynical-Optimist wants to merge 15 commits intocodethink/typescript-codecfrom
Conversation
ghost
left a comment
There was a problem hiding this comment.
The structure and flow seems fine, I have various comments around naming things (the hardest problem in CS). I am also a bit worried by how much duplicated code we're adding, I wonder if it's worth waiting until we deduplicated the codecs code a bit to merge the whole thing, rather than landing this now.
| } | ||
|
|
||
|
|
||
| inputArg : TS.Expression |
There was a problem hiding this comment.
It seems weird to have this at the top of the MapTypes module. I was thinking about moving codec-related stuff into a separate module, and perhaps it'd make sense there.
There was a problem hiding this comment.
My instinct is to have simple utility values like this defined near the top, where they're easy to find when you want to reference them and check what they are.
Happy to put it wherever you think is better though. And I agree, we can probably make a new module for coders and decoders.
| ] | ||
| } | ||
|
|
||
| constructorToCase : ConstructorDetail ta -> ( TS.Expression, List TS.Statement ) |
2606764 to
28ca052
Compare
…codec Generate JSON codecs for TypeScript
Added some docs about the project setup in the contribution guide.
…docs Add documentation for TypeScript backend
Skeleton implementation of multiary decision tree data structure.
Makes it possible for any function declaration to have generic type variables, and a return-type annotation.
IntLiteralExpression: An expression consisting of a literal integer IndexedExpression: An expression for square bracket indexing (eg foo[bar]) SwitchStatement: A switch statement, with a list of cases FunctionTypeExpression: a Type Expression for a function type (a list of parameter types, and a return type)
Puts type annotations on custom type decoders and on type alias decoders Updates how custom type decoders work.
Update the encoder function for custom types and custom type variants. These functions now create the return values directly, and do not have to call on codec.encodeCustomType and codec.encodeCustomTypeVariant.
cf40d83 to
5ddaabc
Compare
decodeContainerType<ContentType>())Re the last 2 points: after adding type annotations we started getting typescript compiler errors in some of our decode functions. The annotations gave the compiler enough information to work out what outputs it expected from the codecs.ts functions, but it couldn't confirm that those codecs.ts functions would return the correct value.
By changing the annotations in codecs.ts, those functions now promise to return the correct types. This doesn't remove the error (the TypeScript compiler is still unable to confirm that the codecs.ts functions will return the types that they promise to return) but now the error has been moved. Instead of dozens of errors in the generated code, we now have exactly two compiler errors in codecs.ts.
And we're able to silence those two specific errors using comments that tell the typescript compiler to ignore them. We can safely do this if (and only if) we're absolutely sure that the logic inside the functions does give the correct results.
Terms