Conditional typescript in this Svelte 5 component #16089
Replies: 3 comments 6 replies
-
As far as I know the first parameter of an event is the type of the event itself <DateComponent
onchange={(e) => handleChange(e, dates)}
/> |
Beta Was this translation helpful? Give feedback.
-
Most likely the problem is that Try this: type SingleDateProps = BaseProps & {
dates?: Date | null;
onchange?: (e: Date | undefined) => void;
};
type RangeDateProps = BaseProps & {
range: true;
dates?: Date[] | null;
onchange?: (e: Date[] | undefined) => void;
}; Basically, remove |
Beta Was this translation helpful? Give feedback.
-
This looks like a potential bug, bare TS works. (Type issues belong in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have this Svelte 5 code:
in this component the
dates
are properly seen likedates: Date[] | undefined
(note therange
prop):if I use this component instead (without the
range
prop):dates
now is seeing likeany
:Why?
Beta Was this translation helpful? Give feedback.
All reactions