Comments (6)
+1 for this.
with ts-pattern, I always use { TAG:0 } instead of { __:'OK' }, which leads poor readability.
from ts-belt.
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.
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.
@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.
@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.
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)
- Ts-belt is 4x slower because it uses the arguments object
- Why an Option type instead of `type` | undefined? HOT 4
- Using unions for a result HOT 11
- ts-belt usage example flagged by TypeScript HOT 2
- why not `Do Notation` and `Applicative`
- Misleading annotations for Array.range
- Is this library still being maintained? HOT 1
- 🚧 Announcement: the current state of ts-belt 🚧 HOT 2
- `AR.isOk` and `AR.isError` not defined
- `AR.toOption` for `undefined` promise resolutions resulting in `{ BS_PRIVATE_NESTED_SOME_NONE: 0 }` HOT 1
- O.Option's functions with null literal value behaves differ from with undefined literal values HOT 1
- Can you tell me how to handle multiple Option types? HOT 4
- A.dropWhile is completely broken HOT 1
- `A.take` does not return empty array when `n` greater than length of array (as documented) HOT 2
- foy for the building not working properly HOT 2
- Update benchmarks to latest package versions HOT 4
- Proposal: G.isFinite HOT 1
- suggestion: reboot with rescript core? HOT 3
- snippets, and linter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-belt.