Open Roaders opened 14 hours ago
Hi @Roaders, The convert class is automatically generated by QuickType - I'd refer you to the docs for it, but there are few. There is this article which explains the use case in other languages such as C# (Conversion of String types to stronger types): http://blog.quicktype.io/transformed-string-types/
The type conversion is not as relevant in JS/TS, but it does (for example) convert string dates to the Date class.
A further use case is that the convert class asserts the type of data converted to a JSON string or of a JSON string converted to the generated type objects, outputting a human-readable error message describing an error that broke conversion. This is valuable when doing conversions at runtime and when working with other codebases (which might be handing you invalid objects, which TypeScript will not help you detect or debug at runtime).
It is perhaps something we could add some docs on... Any suggestions for where in the docs to do that?
Question Area
Question
I had always thought that the Convert class in
BrowserTypes
was for serializing and desterilizing messages to strings for passing them across the boundary between apps. I just realised that doesn't really make sense though as we are able to pass whole objects across the channel api and we don't need to convert them to strings.I now assume that the expectation is that we pass objects and not strings?
I don't remember seeing any mention of the Convert class in the protocol docs. I am now wondering what expected use for it is? If it's just something we get for free from the conversion code then that's fine. I just want to make sure I'm not missing something.