When I build my application I get. error TS2339: Property \'split\' does not exist on type \'string | string[]\'.
Property \'split\' does not exist on type \'string[
Brian Ball's solution is working, another approach for handling this situation is square brackets [ ].
For instance
req.headers.authorization[split](//define your conditions here)
For exmaple:
req.headers.authorization[split](",")
The type you are trying to invoke split on is string|string[], which means that value may be either a string or a string[], in order for TypeScript to be happy, BOTH types must have a split method. If you are confident that it will always be a string, either update the definition (if possible) or cast to a string before calling split:
(<string>req.headers.authorization).split
or
(req.headers.authorization as string).split