Coder Social home page Coder Social logo

ts-union's People

Contributors

d2km avatar dependabot[bot] avatar twop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ts-union's Issues

How to check if an `unknown` object is a Union object and narrow type?

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [x] question about how to use this project

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.

Ability to specify discriminator name

  • 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.

Recursive types?

  • 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

How do I create a generic union of all variants?

  • 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> = ???

How to compare two `UnionVal<Record>` for equality?

  • 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.