WebStorm - 参数类型 {providedIn: “root"} 不可分配给参数类型 {providedIn: Type<any>|“根"|空} &amp;可注射提供者 [英] WebStorm - Argument type {providedIn: &quot;root&quot;} is not assignable to parameter type {providedIn: Type&lt;any&gt; | &quot;root&quot; | null} &amp; InjectableProvider

查看:43
本文介绍了WebStorm - 参数类型 {providedIn: “root"} 不可分配给参数类型 {providedIn: Type<any>|“根"|空} &amp;可注射提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序从 Angular v5 迁移到 v6,并且在尝试在我的提供程序中指定 providedIn 时遇到以下打字稿错误

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

参数类型 {providedIn: "root"} 不能分配给参数类型 {providedIn: Type |根" |空} &InjectableProvider

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

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

我从 Angular 文档中复制并粘贴了代码 https://angular.io/guide/dependency-注射

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

有什么想法吗?

更新

我创建了一个空白项目 ng new ... 并添加了一个提供者 ng g service my-new-service,在 WebStorm 中打开该项目,一切正常,我在那个虚拟项目中没有遇到任何错误

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

更新

我联系了 WebStorm 支持,结果证明这是 WebStorm 的一个已知错误 https://youtrack.jetbrains.com/issue/WEB-32634

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

更新

Webstorm 2018.1.4(尚未发布)应该会修复该问题,请参阅https://youtrack.jetbrains.com/issue/WEB-32634

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

更新

Webstorm 团队将修复移至 2018.1.5

Webstorm team moved the fix to 2018.1.5

更新

2018 年 6 月 17 日星期日,Webstorm 修复程序已发布

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

推荐答案

信不信由你,我在 Webstorm 中关闭并打开了我的项目,错误就消失了

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

感谢@yurzui 和@AdrianFâciu 的支持

Thx @yurzui and @AdrianFâciu for the support

更新

事实证明这是 Webstorm 中的一个确认错误,后来在 v2018.1.5 中更正并于 2018 年 8 月 17 日星期日发布.我已将我的编辑器更新到此版本,不再遇到此问题

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 问题跟踪器:https://youtrack.jetbrains.com/issue/WEB-32634

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

v2018.1.5 发行说明:https://confluence.jetbrains.com/display/WI/WebStorm+181.5281.31+Release+Notes

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

这篇关于WebStorm - 参数类型 {providedIn: “root"} 不可分配给参数类型 {providedIn: Type<any>|“根"|空} &amp;可注射提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆