Vscode-ng-language-service: Typeching of context doesn't work with custom directives

Created on 13 Feb 2020  Β·  14Comments  Β·  Source: angular/vscode-ng-language-service

🐞 bug report

Affected Package


The issue is caused by package @angular/language-service

Is this a regression?

No

Description

Typechecking of context doesn't work. I have copied the ngIf directive and rename it to myIf to test it:

  • Code image
  • with ngIf test is null image
  • with myIf test is any image

πŸ”¬ Minimal Reproduction

https://github.com/tonivj5/angular-issues-35424-and-35426

πŸ”₯ Exception or Error

None

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.2
Node: 13.7.0
OS: linux x64

Angular: 9.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.2
@angular-devkit/build-angular     0.900.2
@angular-devkit/build-optimizer   0.900.2
@angular-devkit/build-webpack     0.900.2
@angular-devkit/core              9.0.2
@angular-devkit/schematics        9.0.2
@angular/cli                      9.0.2
@ngtools/webpack                  9.0.2
@schematics/angular               9.0.2
@schematics/update                0.900.2
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

Anything else relevant?

bug lib

Most helpful comment

This is a bug. The language service should read from the directive template context rather than provide the one-off typings for ngFor. We already have the infrastructure for getting the template context of a structural directive, so this shouldn't be too difficult to fix..

All 14 comments

I have added a reproduction

Looks like Angular language service supports only build-in ngIf and ngFor directives for such kind of cases
https://github.com/angular/angular/blob/a8609ba0ad2e9c1eec3f59f81468c766bc006b56/packages/language-service/src/expression_diagnostics.ts#L136-L186

Thanks @alexzuza for the info! Then, is it a feature request or a bug? Reading the docs don't notice about that (is this the purpouse of the strictContextGenerics flag?). And in this PR describe how to implement it

I would like to use this feature in my owns directives! :cowboy_hat_face:

This is a bug. The language service should read from the directive template context rather than provide the one-off typings for ngFor. We already have the infrastructure for getting the template context of a structural directive, so this shouldn't be too difficult to fix..

Thanks @ayazhafiz for the clarification :+1:. I think https://github.com/angular/angular/pull/35561 should fix it, shouldn't?

Related https://github.com/angular/vscode-ng-language-service/issues/649 (relation lost in the transfer :rocket:)

Ey @ayazhafiz, I have tryed this feature again with the last release (9.1.0), but it doesn't work :laughing: I don't know if it's a regression of the latest release or never worked (I didn't test it again, I've been very busy until now :sweat_smile:)

I have updated the demo to the latest Angular, and test follow being any. Can this issue be reopen or I should open a new one?

Weird, this should not be the case... what version of the language service/language server extension are you using?

I'm using the latest of both (9.1.0)
image

Hmm okay I will take a look soon


ΠžΡ‚: Toni Villena notifications@github.com
ΠžΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½ΠΎ: Friday, March 27, 2020 8:13:23 AM
ΠšΠΎΠΌΡƒ: angular/vscode-ng-language-service vscode-ng-language-service@noreply.github.com
Копия: hafiz ayaz.hafiz.1@gmail.com; Mention mention@noreply.github.com
Π’Π΅ΠΌΠ°: Re: [angular/vscode-ng-language-service] Typeching of context doesn't work with custom directives (#650)

I'm using the latest of both (9.1.0)
[image]https://user-images.githubusercontent.com/7110786/77770593-c944b900-7045-11ea-8519-98cf2035aad4.png

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/angular/vscode-ng-language-service/issues/650#issuecomment-605054463, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AE6GL6ROVOG3PINAKFIWYLLRJS7BHANCNFSM4KYA6U5Q.

Thanks :+1:

@tonivj5 I see, it doesn't work with the MyIf directive. This is a known problem that won't be fix until we flip the language service to Ivy. Basically the issue is that today the language service cannot resolve generic type parameters.

For NgIf we have a special case to look up the type of the variable bound to the directive, but we can't do this for every custom directive.

So, I will have to wait to use this feature :cry:. I suppose it will happen with Angular 10, won't?

Can this issue hold open meanwhile?

Thanks anyway for the time invested :smile:. I will look forward to this feature :zap:

@kyliau can give us some more insight. Ivy is scheduled to land with 10, right? Do we have an existing issue keeping track of the generic bindings problem?

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sheikalthaf picture sheikalthaf  Β·  5Comments

pfeigl picture pfeigl  Β·  6Comments

MoazAlkharfan picture MoazAlkharfan  Β·  3Comments

MarcOne68 picture MarcOne68  Β·  5Comments

BorntraegerMarc picture BorntraegerMarc  Β·  5Comments