I am currently working on integrating a definition file into an npm package that has dependencies on React.
The specific library in question can be found at https://github.com/eiriklv/react-masonry-component.
In my TypeScript project, I have successfully included the following definition in a custom d.ts
file:
declare module "react-masonry-component" {
import React = __React;
interface MasonryPropTypes {
disableImagesLoaded: boolean;
options: Object;
className: string;
elementType: string
}
export var Masonry: React.Component<MasonryPropTypes, void>;
}
However, when attempting to use the same definition within the package itself (with the correct typings
key set in the package.json
), it does not work as expected. This is likely due to the unrecognized __React
type which is provided through tsd/typings from DefinitelyTyped.
What would be the best approach in this situation? Should we duplicate the declaration for React in order to satisfy the compiler, or is there a way to include React.Component
without duplication?