My inquiry pertains to handling required parameters when an alias is satisfied, which may seem complex initially. To illustrate this concept, let's consider a practical scenario.
If we refer to the Bing Maps API - REST documentation for "Common Parameters and Types" (accessible here: Bing Maps - Common Parameters and Types)
Upon reviewing the documentation, you may notice certain parameter names are aliased.
For instance, imagine a coordinates object containing both latitude and longitude values, each with short aliases - "lat" for latitude, and "lng" for longitude. How can we design types that intelligently accept necessary combinations while disregarding redundant parameters that have already been fulfilled?
type Latitude = { latitude: number } | { lat: number };
type Longitude = { longitude: number } | { lng: number };
type Location = Latitude & Longitude;
function formatLocation(loc: Location) {
//... Performing useful operations
}
formatLocation({
lat: 123.456,
latitude: 123.456, // <--- Ideally, this should trigger an error or be ignored since "lat" is already provided.
longitude: -12.3456
});
I understand that TypeScript's "advanced types" (such as exclude, extract, omit, etc.) offer solutions for this scenario. However, I'm curious if there is a dynamic approach to achieving the same outcome.