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
I don't know if it is possible to solve this but I think it could be helpful if it was. Perhaps I am missing something and there is a better solution.
In the readme it states: "Currently supported Point properties are null, boolean, number, string. The rest will be discarded when the supercluster is created. If you need to store other properties you can always turn them into a JSON."
This makes sense but it would be useful if there was some way of reflecting this in the types to avoid errors where properties other than these types were passed to the class Supercluster.
Currently, the follow code could lead to problems if the an attempt was made to access PointFeature["properties"]["price"]["weekday"] since the type would suggest this property existed when, in fact, this will have been stripped out.
type InternalPointType = {
name: string,
price: {
weekday: number;
weekend: number;
}
}
const superClusterIndex = new Supercluster<InternalPointType >();
In my own code I have used the following type "PickByType" (credits: https://stackoverflow.com/a/69756175) to create a new version of the original type which reflects the runtime object more accurately.
type PickByType<T, Value> = {
[P in keyof T as T[P] extends Value | undefined ? P : never]: T[P];
};
type ClusteredInternalPointType = PickByType<
InternalPointType,
null | boolean | number | string
>
const superClusterIndex = new Supercluster<ClusteredInternalPointType >();
I wonder if a similar technique could be used internally to modify the type passed to Supercluster. I don't think I have a deep enough understanding of this project at the moment to create a pull request but I think this could be helpful if someone else thought this would be useful to implement.
The text was updated successfully, but these errors were encountered:
I don't know if it is possible to solve this but I think it could be helpful if it was. Perhaps I am missing something and there is a better solution.
In the readme it states: "Currently supported Point properties are null, boolean, number, string. The rest will be discarded when the supercluster is created. If you need to store other properties you can always turn them into a JSON."
This makes sense but it would be useful if there was some way of reflecting this in the types to avoid errors where properties other than these types were passed to the class Supercluster.
Currently, the follow code could lead to problems if the an attempt was made to access PointFeature["properties"]["price"]["weekday"] since the type would suggest this property existed when, in fact, this will have been stripped out.
In my own code I have used the following type "PickByType" (credits: https://stackoverflow.com/a/69756175) to create a new version of the original type which reflects the runtime object more accurately.
I wonder if a similar technique could be used internally to modify the type passed to Supercluster. I don't think I have a deep enough understanding of this project at the moment to create a pull request but I think this could be helpful if someone else thought this would be useful to implement.
The text was updated successfully, but these errors were encountered: