0
votes

I saw in Angular's API documentation, it declared HttpRequest's clone() method as such:

clone(update: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; body?: T; method?: string; url?: string; setHeaders?: { ...; }; setParams?: { ...; }; }): HttpRequest

I wonder is "{...;}" construct after "setHeaders?:" property a valid syntax for type declaration in TypeScript, I searched and did not find the spread operator can be used in the type declaration, is this just appears in Angular's documentation only? Thanks.

1

1 Answers

2
votes

The documentation is somewhat confusing. What it's trying to get across is that the setHeaders property may exist, and if it does, it should be an object with properties, as you can see in an example here:

// Clone the request and set the new header in one step.
const authReq = req.clone({ setHeaders: { Authorization: authToken } });

The code verbatim from the documentation is not valid JavaScript or TypeScript.