Skip to content

Instantly share code, notes, and snippets.

@jeffmo
Created April 19, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffmo/55d32d6eddb1f8e7ffb2a95c44549544 to your computer and use it in GitHub Desktop.
Save jeffmo/55d32d6eddb1f8e7ffb2a95c44549544 to your computer and use it in GitHub Desktop.
// @flow
import {connect} from './connect';
type Props = {
name: string,
magic: number,
};
export function MyComponent(props: Props) {
return <div />;
}
export const MyConnectedComponent = connect(MyComponent, { magic: 42 });
// Flow says only `name` is missing, which is correct since we "connected" `magic`
// $ExpectError
//<MyConnectedComponent />;
// export MyConnectedComponent;
// @flow
import {MyConnectedComponent, MyComponent} from './a';
// Flow says `name` and `magic` are missing, which is expected
// $ExpectError
<MyComponent />;
// Flow is fine with this one?
<MyConnectedComponent />;
// @flow
type Component<P> = (props: P) => any;
export function connect<P, E>(component: Component<P>, extra: E): Component<$Diff<P, E>> {
return (component: any);
}
b.js:7
7: <MyComponent />;
^^^^^^^^^^^^^^^ React element `MyComponent`
10: export function MyComponent(props: Props) {
^^^^^ property `magic`. Property not found in. See: a.js:10
7: <MyComponent />;
^^^^^^^^^^^^^^^ props of React element `MyComponent`
b.js:7
7: <MyComponent />;
^^^^^^^^^^^^^^^ React element `MyComponent`
10: export function MyComponent(props: Props) {
^^^^^ property `name`. Property not found in. See: a.js:10
7: <MyComponent />;
^^^^^^^^^^^^^^^ props of React element `MyComponent`
Found 2 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment