Motivation
When interfacing with other libraries/other code, there is sometimes a need for for using the tags from the tagged union. This results in need to define our unions as follows, which is unnecessarily verbose and boilerplateful.
const ON = 'ON';
const OFF = 'OFF';
const State = unionized({
[ON]: ofType<{}>(),
[OFF]: ofType<{}>()
})
// do something later with tag
console.log(ON) // 'ON'
Solution
Expose record tags as a property on the Unionized object.
const State = unionized({
ON: ofType<{}>(),
OFF: ofType<{}>()
})
// do something later with tag
console.log(State.tags.ON) // 'ON'
/*
State.tags is:
{
ON: 'ON';
OFF: 'OFF';
}
*/
Coverage remained the same at 100.0% when pulling 046b830d20456da2b4453e19be375f4714e32054 on GrzegorzKazana:expose-tag-record into 55240dd4229528d050caac0ad6114bce7101fb78 on pelotom:master.
Adresses #75 .
Motivation When interfacing with other libraries/other code, there is sometimes a need for for using the tags from the tagged union. This results in need to define our unions as follows, which is unnecessarily verbose and boilerplateful.
Solution Expose record tags as a property on the
Unionized
object.