You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, the UpdateLocation callback has to return something that implements both proto.example.locations.IAssetLocation and protobuf.Message<proto.example.locations.IAssetLocation>. The problem is, the protobuf compiler doesn't generate anything that implements both of these, it generates this:
/** Properties of an AssetLocation. */interfaceIAssetLocation{/** AssetLocation assetId */assetId?: (string|null);/** AssetLocation location */location?: (string|null);}/** Represents an AssetLocation. */classAssetLocationimplementsIAssetLocation{/** * Constructs a new AssetLocation. * @param [properties] Properties to set */constructor(properties?: example.locations.IAssetLocation);/** AssetLocation assetId. */publicassetId: string;/** AssetLocation location. */publiclocation: string;
So, in my UpdateLocation callback, I can instantiate an AssetLocation, 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:
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.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: