Why is Angular not choosing correct overload for HttpClient.get(…)?

戏子无情 提交于 2019-12-02 10:54:48

This is because you are declaring options with type any.

By doing this, the compiler knows nothing about the interface/members of options, despite the fact that you instantiate its value with an object made of 2 properties.

Refactor into this:

export class Foo {
   private options = {headers: {...}, withCredentials: true};
   ....
}

Now the compiler can infer the type of options, instead of statically reading it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!