glitchwizard
glitchwizard

Reputation: 542

Angular API HttpClient Method definition clarification

I'm reading through the documentation on Angular, trying to understand the syntax of the method definition of the 'post' method for Angular's HttpClient class, and I don't understand what the pipe implies in the definition.

Looking at the header or param definition here, it says:

  params?: HttpParams | { 
    [param: string]: string | string[]; 
  }; 

The full definition is:

post( 
  url: string, 
  body: any, 
  options: { headers?: HttpHeaders | {
     [header: string]: string | string[]; 
   }; 
  observe?: "body"; 
  params?: HttpParams | { 
    [param: string]: string | string[]; 
  }; 
  reportProgress?: boolean; 
  responseType: "arraybuffer"; withCredentials?: boolean; 
})

What does the pipe imply in this definition? I've googled it but there's not much on exactly what that syntax means, I'm new to angular so explanations are very welcome.

My best guess is that it works like an OR operator or something? Is that correct?

Upvotes: 0

Views: 17

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249536

The | introduces a union type as describe here. This has the meaning that params can be either HttpParams or an object with all string or string[] properties ({ [param: string]: string | string[]; })

Upvotes: 1

Related Questions