-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #3609 - Update Calendar typings to be precise #4972
Fixes #3609 - Update Calendar typings to be precise #4972
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Not sure if this helps but in PrimeReact we made the TS even smarter by knowing whether you were in single mode, range mode, or multiple mode. interface CalendarPropsSingle extends CalendarBaseProps {
/**
* Specifies the selection mode either "single", "range", or "multiple";
* @defaultValue single
*/
selectionMode?: 'single' | undefined;
/**
* Value of the component.
* @defaultValue null
*/
value?: Nullable<Date>;
/**
* Callback to invoke when value changes.
* @param { FormEvent<Date>} event - Custom change event
*/
onChange?(event: FormEvent<Date>): void;
}
interface CalendarPropsRange extends CalendarBaseProps {
/**
* Specifies the selection mode either "single", "range", or "multiple";
* @defaultValue single
*/
selectionMode: 'range';
/**
* Value of the component.
* @defaultValue null
*/
value?: Nullable<(Date | null)[]>;
/**
* Callback to invoke when value changes.
* @param { FormEvent<(Date | null)[]>} event - Custom change event
*/
onChange?(event: FormEvent<(Date | null)[]>): void;
}
interface CalendarPropsMultiple extends CalendarBaseProps {
/**
* Specifies the selection mode either "single", "range", or "multiple";
* @defaultValue single
*/
selectionMode: 'multiple';
/**
* Value of the component.
* @defaultValue null
*/
value?: Nullable<Date[]>;
/**
* Callback to invoke when value changes.
* @param {FormEvent<Date[]>} event - Custom change event
*/
onChange?(event: FormEvent<Date[]>): void;
}
export type CalendarProps = CalendarPropsSingle | CalendarPropsRange | CalendarPropsMultiple; |
Hi @Magiczne, There are some conflicts in it. Could you please update it and give an update to Melloware's comment? WDYT? |
@mertsincan will try but probably at the end of the week |
c84f936
to
21e8c83
Compare
@mertsincan updated - since in vue on type level the emits are not aware of props the emits will have to stay as normal interface (updated type value), and only props will be a discriminated union, wchich works perfectly fine when I tested this types locally. Only keep in mind, that this could be a breaking change for users using TypeScript. |
As the calendar only allows to select two values, which one of them can be null (first range item selected, second not) the types should be precise and declared as tuple, and not allow arrays of unspecified length.
Fixes #3609