Open bicknellr opened 1 year ago
I think it would be better if Lit 2's ifDefined
didn't run through this path at all, since it doesn't have any special semantics, but TS seems to be returning the wrong type from checker.getTypeAtLocation(assignment.expression)
during this stack:
in the new test:
assignment.expression
is the Node
with text ifDefined(Math.random() < 0.5 ? 123 : null)
but the result of checker.getTypeAtLocation(assignment.expression)
gives the type "non-null" | 123 | null
despite null
not being possible. Not sure what's going on there yet.
The return type of
ifDefined
is determined with a special rule here:https://github.com/runem/lit-analyzer/blob/92c084da4d33d6fbdd8b29603d2003387e65dbb3/packages/lit-analyzer/src/lib/rules/util/directive/get-directive.ts#L45-L63
But the analyzer doesn't realize that the return type can't be
null
in Lit 2, because it only removesundefined
(matching Lit 1's behavior):https://github.com/runem/lit-analyzer/blob/92c084da4d33d6fbdd8b29603d2003387e65dbb3/packages/lit-analyzer/src/lib/rules/util/directive/get-directive.ts#L52