Intellij creates incomplete method on "Implement all members" for Typescript class

Answered

Hi,

I'm using IntelliJ IDEA 2020.1.3 (Ultimate Edition), Build #IU-201.8538.31, on macOS Catalina 10.15.5. The bundled "JavaScript and TypeScript" repeatedly generates incorrect methods if these methods return an "Observable". For instance, I've got this method defined in an interface:

 get(id: number, type: SEAttachmentType): Observable<string>;

Then I create a class that implements that interface. And then I let Intellij create an implementation of that method. Here's what I get:

  get(id: number, type: SEAttachmentType): <string>{
return undefined;
}

So the method is missing the "Observable" in front of "<string>" for the return type. This behavior is documented in a little movie at the end of this post.

Is there a way to get around this bug?

I've used Intellij daily to develop in Angular for two years now, always updating quickly to the latest version I don't think it's always been like this. I'd say that bug showed up a few weeks, maybe a few months ago.


Regards,
Karsten Silz

 

7 comments
Comment actions Permalink

Can't reproduce in 2020.1.3.

For the code like

import {Observable} from "rxjs";

interface SEAttachmentType {}

export interface ITest {
get(id: number, type: SEAttachmentType): Observable<string>;
}


export class Test implements ITest {}

I get the following method when choosing Implement all members:

export class Test implements ITest {
get(id: number, type: SEAttachmentType): Observable<string> {
/** test */

return undefined;
}
}

Can you reproduce the issue in a new project?

0
Comment actions Permalink

Elena Pogorelova, here is a Github repo with a Spring Boot - Angular project: 

https://github.com/ksilz/issue-intellij-typescript-implement-method/tree/master/src/main/webapp/app/issue-demo 

This directory contains the "SInterface" and the "SClass" implementing it. If I pick "Implement all members", the generated code does not contain "Observable":

0
Comment actions Permalink

thanks, reproduced in 2020.1.3. But it's not an issue for me in 2020.2 EAP (https://www.jetbrains.com/idea/nextversion). Could you check if it works for you there?

0
Comment actions Permalink

Elena Pogorelova Sorry, the bug is still in the EAP:

0
Comment actions Permalink

Looks as if it only happens when the referenced library is not included in project index (https://youtrack.jetbrains.com/issue/WEB-46454)

Try marking issue-intellij-typescript-implement-method\node_modules\rxjs as not excluded (Mark directory as/Not excluded) - does it help?

0
Comment actions Permalink

Elena Pogorelova Sorry for the late reply! Yes, marking node_modules\rxjs as not excluded fixed the issue, even in the production version 2020.1.4 (Ultimate Edition), Build #IU-201.8743.12.

So what's the recommendation here? Should I include some of the modules in node_modules? Or all of them?

0
Comment actions Permalink

It's better not to include node_modules manually (if not advised like in this case) because it can immensely increase the amount of code to be indexed.

Elena created a bug report (https://youtrack.jetbrains.com/issue/WEB-46454) so our developers will look into this issue.

0

Please sign in to leave a comment.