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
(extracted as new issue from a conversation in #464)
The shape operators returning new shapes are only returning the generic IShape type at current. This is often sufficient, however can cause weird type errors when passing these generically typed results to other functions expecting a concrete shape type. The current solution is to add manual type casts to satisfy the TS compiler, but maybe this can be improved...
I've been trying a few approaches to provide better return types, but none of them are truly "watertight" and/or as extensible as these polymorphic functions are intended to be... e.g. support for custom shape types can be added via e.g. flip.add("myshapeid", (shape) => { ... }) and this can be done for almost all of the thi.ng/geom functions... but that flexibility comes at a price, i.e. only a generic return type...
At least for the built-in types, a possible solution could involve function overrides and/or mapped types, possibly by renaming the actual thi.ng/defmulti-based polymorphic functions to something else (e.g. functionName => functionNameImpl) and exposing the new function overrides as the main API...
The issue is also quite complex to solve, because some of these operators are resulting in a different shape type than the input shape. Sometimes this predictable, other times, depends on optional parameters given... E.g. non-uniformly scaling a circle, triggers a conversion to an ellipse; rotating a rectangle results in a quad, etc.
The text was updated successfully, but these errors were encountered:
(extracted as new issue from a conversation in #464)
The shape operators returning new shapes are only returning the generic
IShape
type at current. This is often sufficient, however can cause weird type errors when passing these generically typed results to other functions expecting a concrete shape type. The current solution is to add manual type casts to satisfy the TS compiler, but maybe this can be improved...I've been trying a few approaches to provide better return types, but none of them are truly "watertight" and/or as extensible as these polymorphic functions are intended to be... e.g. support for custom shape types can be added via e.g.
flip.add("myshapeid", (shape) => { ... })
and this can be done for almost all of the thi.ng/geom functions... but that flexibility comes at a price, i.e. only a generic return type...At least for the built-in types, a possible solution could involve function overrides and/or mapped types, possibly by renaming the actual
thi.ng/defmulti
-based polymorphic functions to something else (e.g.functionName
=>functionNameImpl
) and exposing the new function overrides as the main API...The issue is also quite complex to solve, because some of these operators are resulting in a different shape type than the input shape. Sometimes this predictable, other times, depends on optional parameters given... E.g. non-uniformly scaling a circle, triggers a conversion to an ellipse; rotating a rectangle results in a quad, etc.
The text was updated successfully, but these errors were encountered: