Translate

[TypeScript] TS2345 Argument of type A is not assignable to parameter of type A 이슈




Framework: Angular 4


HTTP 요청에 파라미터를 추가하여 날리기 위해 URLSearchParams 에서 AppendAll 메소드를 사용하는데 아래와 같이 오류가 발생을 했다.



1004lucifer

TS2345:Argument of type 'URLSearchParams' is not assignable to parameter of type 'URLSearchParams'. Property 'rawParams' is missing in type 'URLSearchParams'.

(URLSearchParams 를 URLSearchParams 파라미터로 할당할 수 없다고!???)





알고보니 좀 허무했는데..

Angular 에 URLSearchParams 라는 클래스가 있고,
TypeScript 자체에 URLSearchParams 라는 인터페이스가 있다.
1004lucifer
Angular의 URLSearchParams를 사용해야 했는데 import를 하지 않으니 TypeScript의 URLSearchParams를 기본으로 사용을 해서 문제가 되었다.





다음과 같이 Angular 의 해당 클래스를 import 해주니 문제가 없어졌다.





참고:
https://github.com/Microsoft/TypeScript/issues/9358


댓글