Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support literal type in eb.case #1286

Open
pyb0987 opened this issue Dec 3, 2024 · 2 comments
Open

support literal type in eb.case #1286

pyb0987 opened this issue Dec 3, 2024 · 2 comments
Labels
breaking change Includes breaking changes enhancement New feature or request typescript Related to Typescript

Comments

@pyb0987
Copy link

pyb0987 commented Dec 3, 2024

Hi, thank you for making and developing this amazing library!
I think this might enhance type guard of kysely.

      eb
        .case()
        .when('user.height', '>=', '170')
        .then('tall')
        .else('short')
        .end()
        .as('desc') // this returns type desc: string

I hope this return 'tall' | 'short'.

@koskimas
Copy link
Member

koskimas commented Dec 6, 2024

Does it work if you use 'tall' as const and 'short' as const?

@igalklebanov igalklebanov added enhancement New feature or request typescript Related to Typescript labels Dec 6, 2024
@igalklebanov
Copy link
Member

igalklebanov commented Dec 6, 2024

Hey 👋

For now, what @koskimas suggested works.

In the future, we could use const type parameters in then and else, to provide a tighter experience. These modifiers were introduced in TypeScript 5.0, released on March 16th, 2023.

The case builder was built around a time when that TypeScript version was less than a month old (too new).

According to some processing I did, moving from 4.7 as the minimum TypeScript version to 5.0 is a move from ~85% of the weekly TypeScript downloads to ~64% of the weekly TypeScript downloads.

@igalklebanov igalklebanov added the breaking change Includes breaking changes label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Includes breaking changes enhancement New feature or request typescript Related to Typescript
Projects
None yet
Development

No branches or pull requests

3 participants