Skip to content

Commit

Permalink
XOR3 added
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRefactoring committed Oct 11, 2023
1 parent 13e75c1 commit 031b314
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ export namespace Config {
export type BaseRequestConfig = RequestConfig;
export type Error = AxiosError;

export type Authentication = UtilityTypes.XOR<
export type Authentication = UtilityTypes.XOR3<
{
personalAccessToken: Authentication.PersonalAccessToken;
},
UtilityTypes.XOR<
{
basic: Authentication.Basic;
},
{
oauth2: Authentication.OAuth2;
}
>
>;

export interface Middlewares {
Expand Down
9 changes: 9 additions & 0 deletions src/utilityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ export namespace UtilityTypes {

/** Get the XOR type which could make 2 types exclude each other */
export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;

export type XOR3<T, U, V> =
(T | U | V) extends (infer R)
? (R extends T ? (U | V) : R) extends R
? (R extends U ? (T | V) : R) extends R
? (R extends V ? (T | U) : never)
: never
: never
: never;
}

0 comments on commit 031b314

Please sign in to comment.