unsplash / sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
https://unsplash.github.io/sum-types/
MIT License
42 stars 2 forks source link

Improve appearance of nullary members in console logs #48

Open OliverJAsh opened 1 year ago

OliverJAsh commented 1 year ago

I'm not sure if this is possible.

Currently nullary members appear as functions. It's difficult to view the contents (tag and value).

image

console.dir helps because it allows us to inspect properties on the function:

https://user-images.githubusercontent.com/921609/198569067-ad6e2aae-04e5-4360-98a9-264dee63d725.mov

samhh commented 1 year ago

The most relevant issue is #44 and its fix #45. A less hacky solution would solve this but I couldn't think of anything else at the time that didn't have worse tradeoffs.

In Haskell-land you can't print without a Show instance. I know we're taking a similar approach on Web. It's not quite as ergonomic mind given the need to pass typeclass instances around.

It looks like we could do something like this on Node but I don't know about browsers:

> { [Symbol.for('nodejs.util.inspect.custom')]: () => 'foo' }
foo