-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[lit-html] when directive should have better type def #4085
Copy link
Copy link
Closed
Description
Should this be an RFC?
- This is not a substantial change
Which package is this a feature request for?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
It would be useful for the when directive to guard and properly type its checked value.
For example:
const val: number|null|undefined = 2;
const fn = (v: number)=>v;
when(
val,
// type error because val can be undefined
()=>fn(val)
)In reality val can't be undefined because of the checks in when.
Alternatives and Workarounds
A possible non breaking change solution could be to pass our guard types thru a param to the trueCase and falseCase fn.
const val: number|null|undefined = 2;
const fn = (v: number)=>v;
when(
val,
// when passes value to trueCase and `v` is Exclude<typeof val, undefined|null|false>
(v)=>fn(v)
)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
✅ Done