ts-belt icon indicating copy to clipboard operation
ts-belt copied to clipboard

Typescript error from Result example

Open assertnotnull opened this issue 1 year ago • 2 comments

Using version 3.13.1

There's a type mismatch between the Result functions

image

assertnotnull avatar Mar 22 '23 16:03 assertnotnull

It seems the example should change like this:

pipe(
  // ⬇️ const obj: User = { name: 'Joe', age: 20 }
  R.fromNullable(obj, String('cannot be nullable')),
  R.flatMap((obj) => {
    return G.isNotNullable(obj.name) ? R.Ok(obj) : R.Error(String('missing name'))
  }),
  R.map((obj) => `${obj.name} is ${obj.age} year old!`)
) // → Ok('Joe is 20 year old!')

Those literal strings are regarded as the type of itself instead of a string type.

JUSTIVE avatar Apr 25 '23 10:04 JUSTIVE

seems this issue is resolved in the ts-beltv4.

JUSTIVE avatar Jan 05 '24 01:01 JUSTIVE