Open okian opened 8 years ago
@marudor thanks for putting that together! One thing you'll want to do is to add the type params to React.Component: https://github.com/facebook/flow/blob/f42a31cd1863be1aca7e6a002d1e4a2e92844712/lib/react.js#L16, particularly in the wrapper case:
(config: Object): (reactClass: React.Component) => React.Component;
should be:
<T: ReactClass>(reactClass: T) => T;
<T: ReactClass>(config: Object): (reactClass: T) => T;
That way you won't lose typing when using React components wrapped with Radium.
Actually they changed the React behavior in v0.22. You shouldn't use the type params to React.Component anymore.
Note, I updated my comment above as well.
@marudor, that is for when you are declaring components. In this case, the function actually takes a ReactClass, and returns an identical ReactClass, so we should use type parameters with constraints. You also need the type params on component for Style and StyleRoot, otherwise flow will not do any prop checking on them.
You can see the problems with your current types in this tryflow example. I don't think you were getting errors because of the ordering of the two callable signatures:
http://tryflow.org/#6413a371cd098891c05b72aa37a3d1ee
In the end, the type should look like this:
import React from 'react';
declare module 'radium' {
type RadiumConfig = {
// Copy from https://github.com/FormidableLabs/radium/blob/master/src/config.js
};
declare class Radium {
<T: ReactClass>(reactClass: T) => T;
<T: ReactClass>(config: RadiumConfig): (reactClass: T) => T;
keyframes(animationObject: Object, name?: string): string;
Style: React.Component<{scopeSelector: string}, {config?: ?RadiumConfig, rules: Object, scopeSelector?: ?string>;
StyleRoot: React.Component;
getState(state: Object, componentRef: string, property: string): boolean;
}
declare var exports: Radium;
}
Indeed. Gonna update my defs. Thanks.
Are there any temporary definitions i can use? Thanks!
I made flow libdefs. These might help if someone wants to create Typescript definitions. https://github.com/marudor/flowInterfaces/blob/master/packages/iflow-radium/index.js.flow