3 ms·
> some fields would randomly be missing, because the field wasn't necessary for that instance of the object This problem can occur in statically-typed language
by MaxBarraclough 7y ago
> some fields would randomly be missing, because the field wasn't necessary for that instance of the object
This problem can occur in statically-typed languages too, such as if you have a class to model your entity, but in this instance you only need certain fields to be hydrated. The other fields may be set to null.
This might only a problem if the half-populated instance is 'leaked' to somewhere that expects a fully hydrated instance. Thinking about it though, it's possible that null could also be used to represent a null held on the database, rather than not hydrated.
The ideal solution would I suppose be to roll your own type for this semi-hydrated data, but that's not always possible/convenient.
Example: https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/overview.md#query-options https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/de...
- xsmasher 7y agoTypescript makes it convenient to roll your own type- `let draft : Partial<Foo>;` says that 'draft' is shaped like a Foo, EXCEPT all of the fields are optional. If you try to access a field on draft that doesn't exist on Foo, it's a ts error. If you try to pass draft to a function that takes a Foo, it's a type mismatch.