Closed paarthenon closed 3 years ago
Implemented in 2.1.0-beta.0
available via variant@test
Requires TS 4.1
Use as
export const ScopedAnimal = scopedVariant('animal', {
dog: fields<{...}>(),
bird: {},
});
then to match
const func = (anim: ScopedAnimal) => match(descope(anim), {
dog: constant(4),
default: constant(5),
});
Documentation is now available here:
https://paarthenon.github.io/variant/docs/use/advanced-creation#scoped-variants
This will be released as part of variant 3.0 and is available now in variant@dev
As things are each variant is compared purely based on
type
value, which means there can be name conflicts if you set up multiple actions.AppAction
andRequestAction
may both contain aLoadTodos
action, which will cause a conflict if an action ofRequestAction
is checked to beisOfType(_____, AppAction)
because it will wrongfully return true.Scoped types (
@action/TYPE
) are the resolution to this, and TypeScript's 4.1 string templating features make this an ideal feature for this library.I have already implemented a version of this, but there remains a discussion on which delimiter is most appropriate. Also to allow for users who have not yet updated, TypeScript 4.1-specific features will be released in variant
2.1+
.