title: Typescript Intersection / Union / Partial / assertion magic
body: <p>I have the following type:</p>
  <pre><code>export interface SphericalPolarCoordinate {
    /**
     *
     * @param ϕ - the azimuth / right ascension (in degrees)
     *
     */
    ϕ: number
    /**
     *
     * @param θ - the altitude / declination (in degrees)
     *
     */
    θ: number
  }
  </code></pre>
  <p>Which I use in the following function:</p>
  <pre><code>export const getAngularSeparation = (
    coord1: SphericalPolarCoordinate,
    coord2: SphericalPolarCoordinate
  ): number =&gt; {
    // Convert to radians:
    const ϕ1 = convertDegreeToRadian(coord1.ϕ)
    const θ1 = convertDegreeToRadian(coord1.θ)
    const ϕ2 = convertDegreeToRadian(coord2.ϕ)
    const θ2 = convertDegreeToRadian(coord2.θ)
  
    ...
  }
  </code></pre>
  <p>However, I want to be able to pass in either of the two following types:</p>
  <pre><code>export type HorizontalCoordinate = {
    /**
     *
     * is the angle of the object around the horizon, usually measured from true north
     * and increasing eastward
     *
     */
    az: number
    /**
     *
     * Altitude is the angular distance of an object above the local horizon
     *
     */
    alt: number
  }
  </code></pre>
  <p>or</p>
  <pre><code>export type EquatorialCoordinate = {
    /**
     *
     * right ascension, in astronomy, the east–west coordinate by which the position
     * of a celestial body is ordinarily measured; more precisely, it is the angular
     * distance of a body's hour circle east of the vernal equinox, measured along
     * the celestial equator (in unit degrees)
     *
     */
    ra: number
    /**
     *
     * angular distance north or south from the celestial equator measured along a
     * great circle passing through the celestial poles (in unit degrees)
     *
     */
    dec: number
  }
  </code></pre>
  <p>And perform some mapping / Typescript Union / Partial / casting magic, or assertion magic, to be able to pass in any Coordinate that loosely matches the SphericalPolarCoordinate base ...</p>
  <p>Would anyone have an idea as to how this could be achieved?</p>
  <p>I'm thinking it is something along the lines of:</p>
  <pre><code>type MappedTypeWithNewProperties&lt;Type&gt; = {
    [Properties in keyof Type as NewKeyType]: Type[Properties]
  }
  </code></pre>