twop / ts-union Goto Github PK
View Code? Open in Web Editor NEWADT sum type in typescript
License: MIT License
ADT sum type in typescript
License: MIT License
Great library! It'd be even more useful if it supported Haskell's Either
type.
If I have some arbitrary union like:
const MyUnion = Union({
Str: of<string>(),
Num: of<number>()
})
type MyUnion = typeof MyUnion.T
And I have a function that maybe throws a MyUnion
:
try {
foobar();
}
catch (err: unknown) {
// ?? how to tell if `err` is a `MyUnion` here?
}
How can I tell if the returned value is a MyUnion
? There doesn't seem to be any function in the API like MyUnion.is(maybeAUnion)
that could narrow the type.
I'm submitting a ...
[x] question about the decisions made in the repository
[x] question about how to use this project
Summary
Why should I use this library over the other one?
I'm submitting a ...
[ ] bug report
[ x ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
Something unionize
has and can be of use if you need to deal with well established contract like FSA. Currently, I'd need to manually extend the result object influencing performance and - potentially, but hopefully not - breaking some existent behaviours.
I'm submitting a ...
[ ] bug report
[x] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
I'm wondering if it's possible to support recursive ADTs, for example a classic linked list. My own attempts at a generalised ADT library have failed in this regard since the TS compiler can't handle the recursive type aliases
I'm submitting a ...
[ ] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[x] question about how to use this project
Summary
How do I create an equivalent of this Rust type, including an interface for all of it's members?
enum LoadingEnum<T> {
Loading,
Loaded(T)
}
const LoadingEnum = Union(T => ({
Loading: of(null),
Loaded: of(T)
}));
type LoadingEnum<T> = ???
I'm submitting a ...
[ ] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[โ
] question about how to use this project
Summary
Is there a way to compare two UnionVal<Record>
for equality?
My scenario is: nested routes, so I want to construct some matcher functions (exact, leftside a -> b, ...) with a signature like <Record, T = UnionVal<Record>>(a: T, b: T) => boolean
.
So far I have managed to get it done by comparing .k
and then .p
, but the docs say that the runtime API is not stable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.