jamesmcnamara / shades

A lodash-inspired lens-like library for Javascript
MIT License
413 stars 14 forks source link

Types not resolving properly with TypeScript 3.8.2 #36

Closed cowboyd closed 2 years ago

cowboyd commented 4 years ago

Hello,

Thank you for the great library and the thoughtful README. This api is very user-friendly.

I'm evaluating shades as a replacement for ramda lenses since we're having a devil of a time with Ramda lenses and TS. Shades looks like it's got a lot of promise in this direction, so we're very interested in seeing how it will work.

I ran into a stumbling block pretty early on when composing lenses with the get method. TypeScript thinks that get('user', 'username') is a function that returns undefined. Specifically

<S extends HasKey<"user", HasKey<"username", any>>>(s: S) => undefined

The get itself works, but you can't actually use any values produced by it in TypeScript because the compiler thinks it's undefined and therefore unsafe.

Here are some screenshots showing the errors:

image

image

image

Here is the repo I'm using https://github.com/cowboyd/shades-test

jamesmcnamara commented 4 years ago

Oooh very interesting. I haven't tested this with 3.7 or above, I'll try to carve some time and investigate. Handling possibly undefined values has been a real bear for this library.

jamesmcnamara commented 2 years ago

This is resolved in later versions of TS; I'm publishing shades@2.2 later today which will update all dependencies.