Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Implicit Types - Push and Let directives #795

Closed
wSedlacek opened this issue May 31, 2021 · 12 comments
Closed

Incorrect Implicit Types - Push and Let directives #795

wSedlacek opened this issue May 31, 2021 · 12 comments

Comments

@wSedlacek
Copy link

There seems to be some thing going on with the types the Angular Language Service is picking up for these directives.

Push Directive

transform(
potentialObservable: null,
config?: string | Observable<string>,
renderCallback?: NextObserver<U>
): null;
transform(
potentialObservable: undefined,
config?: string | Observable<string>,
renderCallback?: NextObserver<U>
): undefined;
transform(
potentialObservable: ObservableInput<U>,
config?: string | Observable<string>,
renderCallback?: NextObserver<U>
): U;
transform(
potentialObservable: ObservableInput<U> | null | undefined,
config: string | Observable<string> | undefined,
renderCallback?: NextObserver<U>
): U | null | undefined {
if (config) {
this.strategyHandler.next(config);
}
this.templateObserver.next(potentialObservable);
return this.renderedValue as U;
}

Example

Screen Shot 2021-05-30 at 6 23 10 PM

Screen Shot 2021-05-30 at 6 22 35 PM

Screen Shot 2021-05-30 at 6 22 20 PM

Angular Reference

Async Pipe

Let Directive

/** @internal */
function createViewContext<T>(value: T): RxLetViewContext<T> {
return {
rxLet: value,
$implicit: value,
$error: false,
$complete: false,
$suspense: false,
};
}

Example

Screen Shot 2021-05-30 at 6 28 30 PM

Screen Shot 2021-05-30 at 6 27 40 PM

Screen Shot 2021-05-30 at 6 28 23 PM

Angular Reference

NgIfContext

@arturovt
Copy link
Member

Hey @wSedlacek , thanks for the issue!

Could you, please, provide a minimal reproducible example or elaborate more on the question (e.g. what version are you using)?

I've just tried to reproduce your issue with rxLet but I can't, see my screenshots:

image

image

But I was able to reproduce the push pipe issue, it's fixed in the current repository but the new version is not published yet :)

@wSedlacek
Copy link
Author

I'll get repo up. Thanks for looking into it!

@wSedlacek
Copy link
Author

So I have narrowed down the issue to only occurring when using the View Engine for the Angular Language Service.

Version


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 12.0.2
Node: 14.17.0
Package Manager: pnpm 6.6.2
OS: darwin x64

Angular: 12.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.2
@angular-devkit/build-angular   12.0.2
@angular-devkit/core            12.0.2
@angular-devkit/schematics      12.0.2
@schematics/angular             12.0.2
rxjs                            6.6.7
typescript                      4.2.4
    "@rx-angular/cdk": "^1.0.0-alpha.8",
    "@rx-angular/template": "^1.0.0-beta.25",

Reproduction

https://github.com/wSedlacek/rx-example

@lincolnthree
Copy link
Contributor

Just FYI, I believe there is currently a regression in Angular itself, even with the patched version this is not working right now:

angular/vscode-ng-language-service#1388

@atscott
Copy link

atscott commented Jun 7, 2021

The linked issue of the language service is unrelated to types and there's no regression on types that we're aware of. It sounds like this is likely due to not having the correct compiler options enabled to get the most specific types. Can you try enabling strictTemplates in your tsconfig?

@lincolnthree
Copy link
Contributor

@atscott I will reply there.

@DPros
Copy link

DPros commented Jul 6, 2021

Hi, I am also having troubles with push pipe typing in 1.0.0-beta.25: the value it produces is typed as any. Is there any reason to specify the U parameter in class declaration export declare class PushPipe<U> implements PipeTransform, OnDestroy { ? Shouldn't the transform method be parametrized instead (e.g. transform<U>(potentialObservable: ObservableInput<U>, config?: string | Observable<string>, renderCallback?: NextObserver<U>): U;), just like async pipe does it?

@UrKr
Copy link

UrKr commented Jul 10, 2021

Hi, I am also having troubles with push pipe typing in 1.0.0-beta.25: the value it produces is typed as any. Is there any reason to specify the U parameter in class declaration export declare class PushPipe<U> implements PipeTransform, OnDestroy { ? Shouldn't the transform method be parametrized instead (e.g. transform<U>(potentialObservable: ObservableInput<U>, config?: string | Observable<string>, renderCallback?: NextObserver<U>): U;), just like async pipe does it?

Are you only experiencing this issue with the push pipe or rxLet also? For me it's not working with either.
image

This has no effect.

  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "preserveWhitespaces": true
  }

@UrKr
Copy link

UrKr commented Jul 10, 2021

I resolved the issue with rxLet by updating my VisualStudio code and the Angular Language Service extension... though it wasn't particularly obvious that the extension had been updated. I had to go the the extension page and press the "reload required" button.

Oh, and I had to add strictTemplates: true

@lincolnthree
Copy link
Contributor

I've also discovered that sometimes the VSCode workspace seems to get "corrupted" and the Angular Language Service stops working properly on external directives like this. I re-created the workspace with default settings and it started to work again.

@BioPhoton
Copy link
Member

So ill close this one as not a bug anymore. Feel free to reopen at any time.

@DPros
Copy link

DPros commented Aug 15, 2021

Hi, I am also having troubles with push pipe typing in 1.0.0-beta.25: the value it produces is typed as any. Is there any reason to specify the U parameter in class declaration export declare class PushPipe<U> implements PipeTransform, OnDestroy { ? Shouldn't the transform method be parametrized instead (e.g. transform<U>(potentialObservable: ObservableInput<U>, config?: string | Observable<string>, renderCallback?: NextObserver<U>): U;), just like async pipe does it?

Hi again. I am using Intellij Idea, not VSCode, and I could not find a solution to resolve this issue from my side. I tried editing the source code of the push pipe (added <U> parameter to the transform method), and it resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants