Open jroper opened 1 year ago
Yes, one of the last awkward leftovers for the TypeScript SDK. It's because of the requirement to know the type for serialising states, which was only available in the reflective messages, not the statically generated ones. It can be fixed now that the generated static types have the type url in the new protobufjs release. Already tracked by #326.
When we generate typescript interfaces, we generate interfaces like this:
So, the
UpdateLocation
callback has to return something that implements bothproto.example.locations.IAssetLocation
andprotobuf.Message<proto.example.locations.IAssetLocation>
. The problem is, the protobuf compiler doesn't generate anything that implements both of these, it generates this:So, in my
UpdateLocation
callback, I can instantiate anAssetLocation
, but I can't return it, that will fail type checking. There's nothing that I can return. What we tell people to do is to do this:And that works, but the problem is that
AssetLocation
has a type ofMessage<{}>
, so now we have lost type safety. I could do:That doesn't compile if I used the generated
AssetLocation
class, but does compile, and then fails silently at runtime, with the approach we force users to use.The fact is, for these generated classes, we know exactly what type all the classes should be returning, so the metadata that we require to be there and extract from
protobuf.Message
shouldn't be necessary.