react-sizes
react-sizes copied to clipboard
Add typescript typings
any news? )
Unfortunately not, but we are open to pull-requests if anyone is willing to help!
The following piece in the declarations.d.ts works for me with the withSizes function:
declare module 'react-sizes' {
export interface Sizes {
width: number | false;
height: number | false;
}
type mapSizesToProps<SP extends object> = (sizes: Sizes) => SP;
export function withSizes<SP extends object, P extends SP>(
mapSizesToProps: mapSizesToProps<SP>,
): (component: React.ComponentType<P>) => React.ComponentType<P>;
export default withSizes;
}
Note: This way, the output component expects the same props as the input component. Since withSizes already sets some props, this might raise issues with mandatory props. Therefore, you could e.g. use the Subtract<T, T1> type of the utility-types package. But I wanted to keep it simple for my use case.
thanks for contributing these types @janKir! I just created a PR to DefinitelyTyped with the types from your comment https://github.com/DefinitelyTyped/DefinitelyTyped/pull/36058
the only modification that I made as to remove the | false from the Sizes interface. In my usage at least, I didn't find a case where either width or height was false or boolean. Otherwise, these type definitions work great in my project.
meant to post this here earlier, but my PR made it into DefinitelyTyped 🎉
you can see the types for react-sizes here:
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-sizes
you can use the types in your TypeScript project with this command:
yarn add -D @types/react-sizes