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

Ngtsc error shown since last Typescript update #29

Open
mcarraragh opened this issue Oct 28, 2024 · 4 comments
Open

Ngtsc error shown since last Typescript update #29

mcarraragh opened this issue Oct 28, 2024 · 4 comments

Comments

@mcarraragh
Copy link

Hi, I've upgraded my Angular project lately (from an earlier 18.X to the 18.2.8) which also upgraded Typescript. Sublime Text is now showing the error "this kind of expression is always falsy" (ngtsc 2873), which is a bit annoying since the code is actually working.

The culprit is the ?. operator whenever I use it on an optional variable. For example: <app-configuration-panel [configuration]="currentApp?.configuration" /> (perfectly valid, the input accepts undefined/null values).

I don't have any TS error if I disable Ngx HTML so I believe that this is the plugin that handles TS's errors in HTML templates. Is there a way to disable specific TS errors? I'd like to keep the ones that cause compilation errors and disable only the 2873. I've tried using tsc-silent but it didn't work.

Thanks for your help!

@princemaple
Copy link
Owner

Disabling this package only makes it not recognised by the language server. This package has nothing to do with diagnosis. It only provides syntax highlighting.

@princemaple
Copy link
Owner

I ran into this problem, too. I haven't got the time to fix it. The fix will probably be in lsp-angular, or in my own configs.

@mcarraragh
Copy link
Author

Ok thanks! I'll check LSP-Angular to see if there's anything there (yet).

@princemaple
Copy link
Owner

princemaple commented Nov 11, 2024

So I finally got to this. Looks like it's because LSP-angular upgraded to ts 5.6 too soon. The fix is easy, though. Simply install @angular/language-server and [email protected] somewhere (in my case at ~/tmp/angular-ls/) and point LSP-angular to use that.

An example for Windows users, *nix users can simply replace the path with *nix format

{
  "command": [
    "${node_bin}", "C:\\Users\\chenp\\tmp\\angular-ls\\node_modules\\@angular\\language-server\\index.js",
    "--logFile", "C:\\Users\\chenp\\tmp\\angular-ls\\ngls.log",
    "--ngProbeLocations", "C:\\Users\\chenp\\tmp\\angular-ls\\node_modules",
    "--tsProbeLocations", "C:\\Users\\chenp\\tmp\\angular-ls\\node_modules",
    "--stdio"
  ],
}

LSP-angular also has an example at the bottom of its readme for projects that have language server package as part of its dependencies, that would work on any platform.

@princemaple princemaple pinned this issue Nov 11, 2024
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

2 participants