From 232d15463dabfb8d2f03d659ad31c23136925642 Mon Sep 17 00:00:00 2001 From: tricinel Date: Mon, 20 Nov 2017 17:57:36 +0100 Subject: [PATCH] Add flow types; related to #24 --- flow-typed/glamor.js | 4 +++ flow-typed/polyfills.js | 11 +++++++ src/components/ErrorDecoder/ErrorDecoder.js | 35 ++++++++++++++------- src/layouts/index.js | 10 +++++- src/pages/docs/error-decoder.html.js | 8 ++++- 5 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 flow-typed/polyfills.js diff --git a/flow-typed/glamor.js b/flow-typed/glamor.js index 1c87bfc2..d6ae5ca4 100644 --- a/flow-typed/glamor.js +++ b/flow-typed/glamor.js @@ -15,3 +15,7 @@ declare module 'glamor/react' { propMerge: Function, }; } + +declare module 'glamor/reset' { + declare module.exports: any; +} diff --git a/flow-typed/polyfills.js b/flow-typed/polyfills.js new file mode 100644 index 00000000..9aa0daec --- /dev/null +++ b/flow-typed/polyfills.js @@ -0,0 +1,11 @@ +declare module 'array-from' { + declare module.exports: any; +} + +declare module 'string.prototype.includes' { + declare module.exports: any; +} + +declare module 'string.prototype.repeat' { + declare module.exports: any; +} diff --git a/src/components/ErrorDecoder/ErrorDecoder.js b/src/components/ErrorDecoder/ErrorDecoder.js index 3e638d61..28bc7db7 100644 --- a/src/components/ErrorDecoder/ErrorDecoder.js +++ b/src/components/ErrorDecoder/ErrorDecoder.js @@ -2,14 +2,14 @@ * Copyright (c) 2013-present, Facebook, Inc. * * @emails react-core + * @flow */ 'use strict'; import React, {Component} from 'react'; -import PropTypes from 'prop-types'; -function replaceArgs(msg, argList) { +function replaceArgs(msg: string, argList: Array): string { let argIdx = 0; return msg.replace(/%s/g, function() { const arg = argList[argIdx++]; @@ -17,7 +17,7 @@ function replaceArgs(msg, argList) { }); } -function urlify(str) { +function urlify(str: string): Array { const urlRegex = /(https:\/\/fb\.me\/[a-z\-]+)/g; const segments = str.split(urlRegex); @@ -25,6 +25,7 @@ function urlify(str) { for (let i = 0; i < segments.length; i++) { if (i % 2 === 1) { segments[i] = ( + // $FlowFixMe: We need to properly trace this error: React element 'a' inconsistent use of library definitions {segments[i]} @@ -36,7 +37,7 @@ function urlify(str) { } // ?invariant=123&args[]=foo&args[]=bar -function parseQueryString(location) { +function parseQueryString(location: Location): null | Array { const rawQueryString = location.search.substring(1); if (!rawQueryString) { return null; @@ -58,7 +59,12 @@ function parseQueryString(location) { return [code, args]; } -function ErrorResult(props) { +type ErrorResultProps = { + code: mixed, + msg: string, +}; + +function ErrorResult(props: ErrorResultProps) { const code = props.code; const errorMsg = props.msg; @@ -79,8 +85,18 @@ function ErrorResult(props) { ); } -class ErrorDecoder extends Component { - constructor(...args) { +type ErrorDecoderProps = { + errorCodesString: string, + location: Location, +}; + +type State = { + code: mixed, + errorMsg: string, +}; + +class ErrorDecoder extends Component { + constructor(...args: Array) { super(...args); this.state = { @@ -109,9 +125,4 @@ class ErrorDecoder extends Component { } } -ErrorDecoder.propTypes = { - errorCodesString: PropTypes.string.isRequired, - location: PropTypes.object.isRequired, -}; - export default ErrorDecoder; diff --git a/src/layouts/index.js b/src/layouts/index.js index 661a4ff4..5ef58119 100644 --- a/src/layouts/index.js +++ b/src/layouts/index.js @@ -2,10 +2,13 @@ * Copyright (c) 2013-present, Facebook, Inc. * * @emails react-core + * @flow */ 'use strict'; +// FIXME: I actually cannot figure out where this Template is used + // Polyfills for IE import 'array-from'; import 'string.prototype.includes'; @@ -23,7 +26,12 @@ import 'glamor/reset'; import 'css/reset.css'; import 'css/algolia.css'; -class Template extends Component { +type Props = { + children: any, // I don't think this is a Node type + location: Location, +}; + +class Template extends Component { render() { const {children, location} = this.props; diff --git a/src/pages/docs/error-decoder.html.js b/src/pages/docs/error-decoder.html.js index 4022677a..d1b0e451 100644 --- a/src/pages/docs/error-decoder.html.js +++ b/src/pages/docs/error-decoder.html.js @@ -2,6 +2,7 @@ * Copyright (c) 2013-present, Facebook, Inc. * * @emails react-core + * @flow */ 'use strict'; @@ -19,7 +20,12 @@ import {createLinkDocs} from 'utils/createLink'; import findSectionForPath from 'utils/findSectionForPath'; import {sectionListDocs} from 'utils/sectionList'; -const ErrorPage = ({data, location}) => ( +type Props = { + data: Object, + location: Location, +}; + +const ErrorPage = ({data, location}: Props) => (