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
The definitions for the City result contains a union type with empty objects that conflict with VSCode intellisense. Note that I'm using the City object as the example, but I see this same issue with other model type definitions::
As you can see, when trying to use the resultant reader value, the editor shows the following errors:
This is because the TS engine assumes the lowest-possible denominator of a union type, so it assumes the empty object {} instead of CountryRecord. The only way around this is to cast the object to a type or interface that removes the union types:
This allows for normal usage, but is a completely unnecessary step. I should also note that ReaderModel should be exported (defined) in your main index module, so importing from @maxmind/geoip2-node/dist/src/readerModel would not become necessary.
There is also an error with the SubdivisionsRecord array, as it's defined.
There is no need to union with an empty array type, as this will hint to the compiler that's an empty array of nothing as opposed to an empty array of SubdivisionsRecord. All this serves to do is erase the type hints for the resultant array. If you're returning an empty array, it can remain the type of the expected array, since it won't be iterated anyways.
It would be better to remove this union type all together and do one of the following, assuming that one of these record sets would not contain a result:
This applies to version 1.6.0
The definitions for the City result contains a union type with empty objects that conflict with VSCode intellisense. Note that I'm using the City object as the example, but I see this same issue with other model type definitions::
As you can see, when trying to use the resultant reader value, the editor shows the following errors:
This is because the TS engine assumes the lowest-possible denominator of a union type, so it assumes the empty object
{}
instead ofCountryRecord
. The only way around this is to cast the object to a type or interface that removes the union types:This allows for normal usage, but is a completely unnecessary step. I should also note that
ReaderModel
should be exported (defined) in your main index module, so importing from@maxmind/geoip2-node/dist/src/readerModel
would not become necessary.There is also an error with the
SubdivisionsRecord
array, as it's defined.There is no need to union with an empty array type, as this will hint to the compiler that's an empty array of nothing as opposed to an empty array of
SubdivisionsRecord
. All this serves to do is erase the type hints for the resultant array. If you're returning an empty array, it can remain the type of the expected array, since it won't be iterated anyways.It would be better to remove this union type all together and do one of the following, assuming that one of these record sets would not contain a result:
The latter of course, would introduce breaking changes but would conform more to JavaScript/NodeJS conventions.
The text was updated successfully, but these errors were encountered: