josdejong / josdejong/typed-function

Possible roadmap feature: Implement subtypes

Open
#140 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
79
Forks
22
PR merge metrics
No merged PRs in 30d

Description

This is a placeholder to not lose track of some discussion in other issues that typed-function could allow clients to declare one type is a subtype of another.

Potential advantages of this include:
* reduce redundancy in type checking/number of type checks (there is no need to reiterate the supertype check in the subtype, the infrastructure will do it for you; and if the supertype check fails, there is no need to test any of its subtypes).
* typed-function can reorder the type checks to avoid "missing" a type because a more inclusive check happens to get ordered before a less inclusive one; hence proper operation of typed-function will be less dependent on getting the order of types exactly right, allowing clients potentially to better spread/modularize addition of types in their code.
* error/sanity checking: illegal to add a conversion from a subtype to a supertype.
* better implementation of type conversions, reduction in redundancy in conversion: a conversion *from* a supertype would work on all its subtypes as well, and a conversion *to* a subtype would convert to all supertypes as well. At the moment, if A is a subtype of B and C is a subtype of D, you might have to define all four conversions from either A or B to C or D as appropriate; with subtyping, depending on the desired behavior, this might well reduce to two conversions or even just one (from B to C).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.