tippyjs
tippyjs copied to clipboard
Adjust types to accept `undefined` props
Problem
TypeScript 4.4 introduced a new compiler option exactOptionalPropertyTypes that fixes some weak typings by differentiating between undefined and "not present" which results in type errors when passing undefined values to tippy's Partial<Props>.
I found this piece of code in src/createTippy.ts which takes care of the undefined props by using removeUndefinedProps onto the passed props:
const props = evaluateProps(reference, {
...defaultProps,
...getExtendedPassedProps(removeUndefinedProps(passedProps)),
});
Solution
That means that we should probably allow undefined as a prop value by adjusting the type of Props because all undefined prop values get stripped away by removeUndefinedProps anyway. Something like this maybe:
type OptionallyUndefined<T> = { [K in keyof T]: T[K] | undefined };
type PassedProps = Partial<OptionallyUndefined<Props>>;
This is how it looks if the exactOptionalPropertyTypes flag is enabled:

Is this something that affects consumers or is it just an internal issue?
It affects customers who have this Typescript flag enabled.