11import { isDestinationFetchOptions } from './destination-accessor-types' ;
2- import type { Xor } from '@sap-cloud-sdk/util' ;
32import type { DestinationFetchOptions } from './destination-accessor-types' ;
43import type { DestinationFromServiceBindingOptions } from './destination-from-vcap' ;
54import type {
@@ -9,6 +8,7 @@ import type {
98 DestinationCertificate ,
109 HttpDestination
1110} from './destination-service-types' ;
11+ import type { WithoutExclusive } from '@sap-cloud-sdk/util' ;
1212
1313/**
1414 * Takes an existing or a parsed destination and returns an SDK compatible destination object.
@@ -469,17 +469,27 @@ export function noDestinationErrorMessage(
469469}
470470
471471/**
472- * Type that is either a {@link HttpDestination} or (XOR) {@link DestinationFetchOptions & DestinationFromServiceBindingOptions}.
472+ * Fetch-options side of the XOR.
473+ *
474+ * `DestinationFetchOptions` requires `destinationName: string`, but when looking up by
475+ * `service` (via `DestinationFromServiceBindingOptions`) we don't have a name. Intersecting
476+ * the two naively makes `destinationName: string & never = never`, killing the service branch.
477+ * Stripping `destinationName` from `DestinationFetchOptions` and letting the inner discriminated
478+ * union of `DestinationFromServiceBindingOptions` own that key fixes it.
473479 */
474- export type DestinationOrFetchOptions = Xor <
475- Destination ,
476- DestinationFetchOptions & DestinationFromServiceBindingOptions
477- > ;
480+ type FetchOptionsLeaf = Omit < DestinationFetchOptions , 'destinationName' > &
481+ DestinationFromServiceBindingOptions ;
482+
483+ /**
484+ * Type that is either a {@link Destination} or (XOR) {@link DestinationFetchOptions} & {@link DestinationFromServiceBindingOptions}.
485+ */
486+ export type DestinationOrFetchOptions =
487+ | ( WithoutExclusive < Destination , FetchOptionsLeaf > & FetchOptionsLeaf )
488+ | ( WithoutExclusive < FetchOptionsLeaf , Destination > & Destination ) ;
478489
479490/**
480- * Type that is either a {@link HttpDestination} or (XOR) {@link DestinationFetchOptions & DestinationFromServiceBindingOptions}.
491+ * Type that is either an {@link HttpDestination} or (XOR) {@link DestinationFetchOptions} & { @link DestinationFromServiceBindingOptions}.
481492 */
482- export type HttpDestinationOrFetchOptions = Xor <
483- HttpDestination ,
484- DestinationFetchOptions & DestinationFromServiceBindingOptions
485- > ;
493+ export type HttpDestinationOrFetchOptions =
494+ | ( WithoutExclusive < HttpDestination , FetchOptionsLeaf > & FetchOptionsLeaf )
495+ | ( WithoutExclusive < FetchOptionsLeaf , HttpDestination > & HttpDestination ) ;
0 commit comments