Skip to content

TypeScript errors with --strictFunctionTypes flag. #391

@a-shtubov

Description

@a-shtubov

reselect: 4.0.0
typescript: 3.2.2

The following code produces TS error.

// tsconfig.json
{
  "compilerOptions": {
    "strictFunctionTypes": true
  }
}
// app.ts
import { createStructuredSelector } from 'reselect';

type GlobalState = {
  foo: string;
  bar: number;
};

const selectFoo = (state: GlobalState) => state.foo;
const selectBar = (state: GlobalState) => state.bar;

const injectState = createStructuredSelector({
  foo: selectFoo, // error
  bar: selectBar, // error
});

Error text

Type '(state: GlobalState) => string' is not assignable to type 'ParametricSelector<{}, {}, string>'.
  Types of parameters 'state' and 'state' are incompatible.
    Type '{}' is missing the following properties from type 'GlobalState': foo, bar [2322]

With strictFunctionTypes disabled, everything works fine. What is the correct way of using createStructuredSelector in TypeScript withstrictFunctionTypes option?

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptIssues related to TypeScript.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions