Closed remziatay closed 1 year ago
Interesting! Yeah, looks like the type inference for T
becomes broader so you'd need to manually provide the types like choose<CheckoutStep, number>
to get it to type check in its current state.
The suggestion of adding the third type parameter extending T
does indeed fix this. It would be good to make it default to T
to make it non-breaking for anyone who actually did specify only 2 type arguments before like
export declare const choose: <T, V, K extends T = T>(value: T, cases: [K, () => V][]) => V;
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
When I use
choose
directive like this, I would expect typescript to throw error since'test'
and'random'
can't be assigned toCheckoutStep
typeReproduction
There should be a type error but there isn't: Typescript gist
Workaround
It's seems like it's because
T
is inferred asstring
since it's used for bothvalue
andcases
paramsIt works as expected when I update the signature like this
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
This never worked
Browser/OS/Node environment
OS: Windows 10 Node version: 18.12.1 npm version: 8.19.2