23

I'm trying to migrate my app from Angular v5 to v6 and I face the following typescript error while trying to specify providedIn in my providers

Argument type {providedIn: "root"} is not assignable to parameter type {providedIn: Type | "root" | null} & InjectableProvider

 @Injectable({
    providedIn: 'root',
 })
 export class MyService {
 }

I copied and pasted the code from the Angular doc https://angular.io/guide/dependency-injection

Any idea?

UPDATE

I have created a blank project ng new ... and added a provider ng g service my-new-service, opened the project in WebStorm and everything was ok, I didn't face any error with that dummy project

UPDATE

I contacted the WebStorm support, it turns out that this is a known bug of WebStorm https://youtrack.jetbrains.com/issue/WEB-32634

UPDATE

Webstorm 2018.1.4 (not yet released) should fix the issue, see https://youtrack.jetbrains.com/issue/WEB-32634

UPDATE

Webstorm team moved the fix to 2018.1.5

UPDATE

Sunday 17th June 2018, the Webstorm fix has been released

David Dal Busco
  • 7,975
  • 15
  • 55
  • 96

2 Answers2

33

Believe me or not, I closed and opened my project in Webstorm and the error just disappeared

Thx @yurzui and @AdrianFâciu for the support

UPDATE

It turns out it was a confirmed bug in Webstorm which was later corrected in v2018.1.5 and published Sunday 17th August 2018. I have updated my editor to this version and didn't face the problem anymore

Webstorm issue tracker: https://youtrack.jetbrains.com/issue/WEB-32634

v2018.1.5 release notes: https://confluence.jetbrains.com/display/WI/WebStorm+181.5281.31+Release+Notes

David Dal Busco
  • 7,975
  • 15
  • 55
  • 96
  • The documentation is quite correct ... here is the proof https://github.com/angular/angular/blob/master/packages/core/src/di/injectable.ts#L71 – Niladri May 06 '18 at 15:26
  • @Niladri agree the documentation is correct, anyway now everything is fine – David Dal Busco May 06 '18 at 15:28
  • Bizarre, restarting Webstorm fixes it for me too, and it then doesn't show up for other newly created services. It then reappears randomly during development. – Chris Brown May 06 '18 at 19:59
  • Kind of weird, today I face the error again and I close/open again my workspace in Webstorm then it's fine... – David Dal Busco May 07 '18 at 08:56
  • I have edited the content of the issue, this is a know bug of Webstorm – David Dal Busco May 07 '18 at 09:28
  • The error appears now only when the TypeScript Language Service is disabled in Preferences | Languages and Frameworks | TypeScript (in this case WebStorm uses its own type checking and it now doesn't work correctly). Can you please check that the service is enabled and there are no errors in the Console tab in the TypeScript tool window? – Ekaterina Prigara May 08 '18 at 09:43
  • @EkaterinaPrigara thx for your feedback! I could confirm that the service "Typescript Language Service" is enabled but I see the following error in the "Typescript console tab": "Error: Timeout on starting language service process" – David Dal Busco May 08 '18 at 10:17
  • @DavidDalBusco we would really appreciate it if you report an issue about the problem with the service here https://youtrack.jetbrains.com/issues/WEB and provide the info about WS and TS version and the IDE logs (menu Help - Show logs). Thank you! – Ekaterina Prigara May 09 '18 at 10:09
  • @EkaterinaPrigara are you sure I should? When I contacted Jetbrains thru the support, you told me it was a duplicate of https://youtrack.jetbrains.com/issue/WEB-32634 – David Dal Busco May 09 '18 at 10:20
0

for me the problem was a wrong import:

import { Injectable } from '@nestjs/common';

I had to change it to:

import { Injectable } from '@angular/core';

Hope that helps someone else!

Oushima
  • 250
  • 3
  • 7