Typescript inspections fail: invalid number of arguments

HI,

working on some frontend code again with my PhpStorm 2017.2.1

It's a fresh react + redux + typescript project so current JS/TypeScript libs are installed.

I have trouble with typescript inspections when trying to connect a react component with redux store using the connect function provided by "react-redux" package. 

TypeScript inspections complain about "Invalid number of arguments, expected 0" in the following code (while TypeScript compiles just fine, only IDE has a problem):

import {eventStreamSelector, isLoadingSelector} from "../selectors/event-stream";
import {default as EventStream, EventStreamProps} from "../components/EventStream";
import {State} from "../../reducer";
import {connect} from "react-redux";

interface PropsFromState extends EventStreamProps {}

const mapStateToProps = (state: State) => ({
isLoading: isLoadingSelector(state),
eventStream: eventStreamSelector(state)
})

const EventStreamContainer = connect<PropsFromState, {}, {}>(mapStateToProps)(EventStream);

export default EventStreamContainer;

"mapStateToProps" is marked red in this line:

const EventStreamContainer = connect<PropsFromState, {}, {}>(mapStateToProps)(EventStream);

 

I managed to disable the inspection for now: Inspections -> TypeScript -> Type mismach

but this disables a way too much checks. Any better ideas would be highly appreciated.

 

 

Regards,

Alex

11 comments
Comment actions Permalink

Can't see errors when using similar code. Sample project that shows up the issue would be helpful.

Also, what function is the error reported for? Please attach a screenshot of error message

0
Comment actions Permalink

thx for your response. I've attached a screenshot. i tried many different combinations (with more arguments and type definitions) but I always get the same error.
But typescript compiles just fine so it really seems to be an IDE thing.

Also checked an older project with similar code and the current version of PhpStorm shows the exact same error for that project, too. Previous PhpStorm version did not show the error (I've created the older project with PhpStorm 163.10504.2)

0
Comment actions Permalink

Strange.. works for me. Please can you provide the app I can use to recreate the issue?

0
Comment actions Permalink

Hello Elena,

thank you for taking the time to look into the issue!

> Strange.. works for me. 

That's really strange. I try to provide more info. I'm out of ideas.

Worked more on the app and recognized that I get the inspection error in many different cases. In fact I'm not able to use PhpStorm for development of the app without adding 

// noinspection TypeScriptValidateTypes

all over the place ...

Whenever a function excepts optional arguments and I want to pass an optional argument, I get this "invalid number of arguments" error.

Here is a very basic demo with a new screenshot:

https://gist.github.com/codeliner/a094a703afd038c4831f93f8025a5d4b

 

As you can see I get the error in a new project with just react and @types/react installed (with yarn). The "React.Component" constructor takes props (and a context) as optional arguments. I just want to pass the props to that constructor and :boom:

I don't have typescript installed locally. We use a docker container with node and typescript similar to that one: https://hub.docker.com/r/sandrokeil/typescript/

So PhpStorm uses the bundled TypeScript version:

PhpStorm info:

PhpStorm 2017.2.1
Build #PS-172.3544.41, built on August 2, 2017
JRE: 1.8.0_152-release-915-b6 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.10.0-28-generic

Let me know what else I can add or try. 

Best regards,

Alex

 

 

 

 

 

 

0
Comment actions Permalink

Thanks, recreated after turning the typescript service off. The problem with connect() was fixed in 2017.2.2 - see https://youtrack.jetbrains.com/issue/WEB-25070

 

issue with

super(props)

also appears to be fixed in 2.2 EAP:

0
Comment actions Permalink

I am currently on IntelliJ 17.2.6, and the problem resurfaces again.  Any TypeScript React components with super(props) are red-flagged.

0
Comment actions Permalink

works for me in IDEA 172.4574 (2017.2.6 RC):

If invalidating caches doesn't help, please provide a test project I can use to reproduce the issue

0
Comment actions Permalink

I have the same problem with js file (react js).

I'm using WebStorm 2017.3.3 

0
Comment actions Permalink

can't recreate; try ctrl+clicking on super - what definition are you taken to?

0
Comment actions Permalink

In my case it leads to node_modules/react-native/jest/mockComponent.js

0
Comment actions Permalink

can you share a sample project that can be used to recreate the issue?

0

Please sign in to leave a comment.