流错误传递对象,具有超出参数需求的额外属性

时间:2018-11-09 19:25:38

标签: flowtype

我有以下代码,其中定义了一个getByIds函数,该函数用于过滤对象数组,每个对象都有一个id字段和其他字段。

// @flow

type X = {
  id: string
};
type F = (Array<string>, Array<X>) => Array<X>;
import { curry } from "ramda";
const getByIds: F = curry((ids, xs) => xs.filter(x => ids.includes(x.id)));

export default getByIds;

在馈送user = {id: 123, alias: 'foo'} to getByIds时,流程会警告X不具有属性alias。我认为流程允许将额外的属性(协变量?)附加到限制类型较少的对象上。

这是eslintrc.js

    module.exports = {
        env: {
            // browser: true ensures things like window, or localStorage won't get complained
            browser: true,
            es6: true
        },
        plugins: [
            "react",
            "flowtype"
            // "prettier",
        ],
        extends: [
            "eslint:recommended",
            // "plugin:react/recommended",
            "plugin:flowtype/recommended"
        ],
        // https://github.com/feross/standard/issues/447
        parser: "babel-eslint",

        parserOptions: {
            ecmaFeatures: {
                modules: true,
                classes: true,
                experimentalObjectRestSpread: true,
                jsx: true
            },
            sourceType: "module"
        },
        rules: {
            // "indent": [
            //     "error",
            //     4
            // ],

            // "prettier/prettier": "error",
            "linebreak-style": ["error", "unix"],
            // "quotes": [
            //     "error",
            //     "double"
            // ],
            // "semi": [
            //     "error",
            //     "never"
            // ],
            // "jsx-space-before-closing": 1,
            // "no-undef": "error",
            "no-unused-vars": [2, { argsIgnorePattern: "_" }], //https://eslint.org/docs/rules/no-unused-vars#argsignorepattern
            "flowtype/define-flow-type": 1,
            "comma-dangle": [1, "always-multiline"],
            "always-multiline": 0,
            "no-console": 0,
            "no-constant-condition": 0,
            "no-case-declarations": 0,
            "react/no-danger": 0,
            "react/display-name": 1,
            "react/jsx-key": 1,
            "react/jsx-no-comment-textnodes": 1,
            "react/jsx-no-duplicate-props": 1,
            "react/jsx-no-target-blank": 1,
            "react/jsx-no-undef": 1,
            "react/jsx-uses-react": 1,
            "react/jsx-uses-vars": 1,
            "react/no-children-prop": 1,
            "react/no-danger-with-children": 1,
            "react/no-deprecated": 1,
            "react/no-direct-mutation-state": 1,
            "react/no-find-dom-node": 1,
            "react/no-is-mounted": 1,
            "react/no-render-return-value": 1,
            "react/no-string-refs": 1,
            "react/no-unescaped-entities": 1,
            "react/no-unknown-property": 1,
            "react/prop-types": 1,
            "react/react-in-jsx-scope": 1,
            "react/require-render-return": 1,
            "react/jsx-max-props-per-line": 1,
            "react/jsx-first-prop-new-line": [1, "multiline-multiprop"],
            "react/jsx-indent-props": [1, 2]
        },
        globals: {
            module: true,
            gon: true,
            require: true,
            __dirname: true,
            _: true,
            jest: true,
            process: true,
            it: true,
            describe: true,
            expect: true,
            test: true,
            SyntheticEvent: true,
            SyntheticAnimationEvent: true,
            SyntheticClipboardEvent: true,
            SyntheticCompositionEvent: true,
            SyntheticInputEvent: true,
            SyntheticUIEvent: true,
            SyntheticFocusEvent: true,
            SyntheticKeyboardEvent: true,
            SyntheticMouseEvent: true,
            SyntheticDragEvent: true,
            SyntheticWheelEvent: true,
            SyntheticTouchEvent: true,
            SyntheticTransitionEvent: true
        },
        settings: {
            flowtype: {
                onlyFilesWithFlowAnnotation: true
            }
        }
    };

有什么想法吗?

0 个答案:

没有答案