Git Product home page Git Product logo

Comments (6)

JUSTIVE avatar JUSTIVE commented on May 29, 2024 1

+1 for this.
with ts-pattern, I always use { TAG:0 } instead of { __:'OK' }, which leads poor readability.

from ts-belt.

mattaiod avatar mattaiod commented on May 29, 2024 1

to solve the problem I mentioned i have created :

export const Left = <T>(error: T): Error<T> => {
  return {
    TAG: 1,
    _0: "data",
    __: "Error",
  };
};

export const Right = <T>(value: T): Ok<T> => {
  return {
    TAG: 0,
    _0: "data",
    __: "Ok",
  };
};

=> so object and type are identical

and in my eslint I have forbidden the use of Ok and Error function :

"no-restricted-syntax": [
      "error",
      {
        "selector": "CallExpression[callee.name='Error']",
        "message": "Error is deprecated, use Left instead because it complies the full type Error of the lib ts-belt.  "
      },
      {
        "selector": "CallExpression[callee.name='Ok']",
        "message": "Ok is deprecated, use Right instead because it complies the full type Ok of the lib ts-belt.  "
      },
]

from ts-belt.

JUSTIVE avatar JUSTIVE commented on May 29, 2024 1

those __:'Ok' | 'Error' s are not belt(the core of this library)'s part. It's added by author @mobily's. It could be cumbersome to match all belt functions to work with __ fields. I'd still recommend using TAG : 0 | 1 field, which could be easily reminded from exit code. Rescript's internal functions use TAG field.

from ts-belt.

mattaiod avatar mattaiod commented on May 29, 2024

@mobily I would like to draw your attention to this very important issue.

Since this library is based on typescript and moreover on functional programming, it is very important that the types and implementation match.

thank you in advance

from ts-belt.

mattaiod avatar mattaiod commented on May 29, 2024

@JUSTIVE Okay, I get the point!

The only potential problem would be if someone used a library or coded something with the same structure, then there would be a conflict.

I mean anything that uses a structure with : TAG : 0 | 1

The best way to avoid this would be to have a key like: BELT_TAG instead of TAG or an other key showing this structure is from ts-belt

-> Of course, I'm aware that this type of conflict may be rare, but I like to use the safest code :)

from ts-belt.

JUSTIVE avatar JUSTIVE commented on May 29, 2024

I see the concerns you have. But I think It's quite a rare to have such type, names.
would be great to adopt your suggestion. I'll make a PR for that, but It'll break codes worked with previous versions.

from ts-belt.

Related Issues (20)

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.