-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[lit-html] Choose directive doesn't check types correctly #4220
Copy link
Copy link
Closed
Labels
Description
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 to CheckoutStep type
type CheckoutStep = 'register' | 'delivery' | 'payment';
function render(step: CheckoutStep) {
return choose(step, [
['test', () => 1],
['random', () => 2],
['register', () => 3],
]);
}Reproduction
There should be a type error but there isn't: Typescript gist
Workaround
It's seems like it's because T is inferred as string since it's used for both value and cases params
export declare const choose: <T, V>(value: T, cases: [T, () => V][]) => V;It works as expected when I update the signature like this
export declare const choose: <T, V, K extends T>(value: T, cases: [K, () => V][]) => V;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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
✅ Done