Skip to content

Commit 232d154

Browse files
committed
Add flow types; related to reactjs#24
1 parent cf2bd4c commit 232d154

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

flow-typed/glamor.js

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ declare module 'glamor/react' {
1515
propMerge: Function,
1616
};
1717
}
18+
19+
declare module 'glamor/reset' {
20+
declare module.exports: any;
21+
}

flow-typed/polyfills.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'array-from' {
2+
declare module.exports: any;
3+
}
4+
5+
declare module 'string.prototype.includes' {
6+
declare module.exports: any;
7+
}
8+
9+
declare module 'string.prototype.repeat' {
10+
declare module.exports: any;
11+
}

src/components/ErrorDecoder/ErrorDecoder.js

+23-12
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
* Copyright (c) 2013-present, Facebook, Inc.
33
*
44
* @emails react-core
5+
* @flow
56
*/
67

78
'use strict';
89

910
import React, {Component} from 'react';
10-
import PropTypes from 'prop-types';
1111

12-
function replaceArgs(msg, argList) {
12+
function replaceArgs(msg: string, argList: Array<any>): string {
1313
let argIdx = 0;
1414
return msg.replace(/%s/g, function() {
1515
const arg = argList[argIdx++];
1616
return arg === undefined ? '[missing argument]' : arg;
1717
});
1818
}
1919

20-
function urlify(str) {
20+
function urlify(str: string): Array<any> {
2121
const urlRegex = /(https:\/\/fb\.me\/[a-z\-]+)/g;
2222

2323
const segments = str.split(urlRegex);
2424

2525
for (let i = 0; i < segments.length; i++) {
2626
if (i % 2 === 1) {
2727
segments[i] = (
28+
// $FlowFixMe: We need to properly trace this error: React element 'a' inconsistent use of library definitions
2829
<a key={i} target="_blank" rel="noopener" href={segments[i]}>
2930
{segments[i]}
3031
</a>
@@ -36,7 +37,7 @@ function urlify(str) {
3637
}
3738

3839
// ?invariant=123&args[]=foo&args[]=bar
39-
function parseQueryString(location) {
40+
function parseQueryString(location: Location): null | Array<any> {
4041
const rawQueryString = location.search.substring(1);
4142
if (!rawQueryString) {
4243
return null;
@@ -58,7 +59,12 @@ function parseQueryString(location) {
5859
return [code, args];
5960
}
6061

61-
function ErrorResult(props) {
62+
type ErrorResultProps = {
63+
code: mixed,
64+
msg: string,
65+
};
66+
67+
function ErrorResult(props: ErrorResultProps) {
6268
const code = props.code;
6369
const errorMsg = props.msg;
6470

@@ -79,8 +85,18 @@ function ErrorResult(props) {
7985
);
8086
}
8187

82-
class ErrorDecoder extends Component {
83-
constructor(...args) {
88+
type ErrorDecoderProps = {
89+
errorCodesString: string,
90+
location: Location,
91+
};
92+
93+
type State = {
94+
code: mixed,
95+
errorMsg: string,
96+
};
97+
98+
class ErrorDecoder extends Component<ErrorDecoderProps, State> {
99+
constructor(...args: Array<any>) {
84100
super(...args);
85101

86102
this.state = {
@@ -109,9 +125,4 @@ class ErrorDecoder extends Component {
109125
}
110126
}
111127

112-
ErrorDecoder.propTypes = {
113-
errorCodesString: PropTypes.string.isRequired,
114-
location: PropTypes.object.isRequired,
115-
};
116-
117128
export default ErrorDecoder;

src/layouts/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
* Copyright (c) 2013-present, Facebook, Inc.
33
*
44
* @emails react-core
5+
* @flow
56
*/
67

78
'use strict';
89

10+
// FIXME: I actually cannot figure out where this Template is used
11+
912
// Polyfills for IE
1013
import 'array-from';
1114
import 'string.prototype.includes';
@@ -23,7 +26,12 @@ import 'glamor/reset';
2326
import 'css/reset.css';
2427
import 'css/algolia.css';
2528

26-
class Template extends Component {
29+
type Props = {
30+
children: any, // I don't think this is a Node type
31+
location: Location,
32+
};
33+
34+
class Template extends Component<Props> {
2735
render() {
2836
const {children, location} = this.props;
2937

src/pages/docs/error-decoder.html.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2013-present, Facebook, Inc.
33
*
44
* @emails react-core
5+
* @flow
56
*/
67

78
'use strict';
@@ -19,7 +20,12 @@ import {createLinkDocs} from 'utils/createLink';
1920
import findSectionForPath from 'utils/findSectionForPath';
2021
import {sectionListDocs} from 'utils/sectionList';
2122

22-
const ErrorPage = ({data, location}) => (
23+
type Props = {
24+
data: Object,
25+
location: Location,
26+
};
27+
28+
const ErrorPage = ({data, location}: Props) => (
2329
<Flex
2430
direction="column"
2531
grow="1"

0 commit comments

Comments
 (0)