Repository: TypeScript
Issue: Parametrized generic intersection type not equivalent to its alias
Labels: Domain: JSDoc,Needs Investigation,Rescheduled

# Bug Report

### 🔎 Search Terms

intersection mapped type generic alias 

### 🕗 Version & Regression Information

It apparently worked in version up to 3.8.
3.9 and 4.0, have an error in both cases
4.1 worked again
4.2 - 4.5 & nightly all have the problem described here


### ⏯ Playground Link


[Playground link with relevant code](https://www.typescriptlang.org/play?jsx=0&ts=4.5.0-beta&filetype=js#code/PTAEAEBcGcFoGMAWBTeBrAUB4AqHHQcJJkBbABwBsBDE0Ab2kgCcBLAOwHNQAfUdgK6kARsmYBfUAGkCRKGSq1kDauwCekgCqzia8sgAmyAGYN6zZNQMB7dpTWgA2gAVQHaQF0A-AC5QmyQAyBlALK1t7UHhrAXZIP0ERMVBxSQBha0pKVEhWW1lgLFx8Ql19I1N6emNraz8mNi5U0AAxWoKivB0oPUMTEIysnLz2AB5E0WYAGlbagD4U2etB7Phc-MJC7C7S+QoaOkYWDm4+CbFJGV2SfaUVdS1ui0gBZnZoMx1QKMzV9fY-CthrZRlIZpo5lMvm53mJ4qAABRoZBqPxg0AAN2olAEyD8mgAlKAALwLDHWVgGKGlVIdaLvSCgUjUZFAtYjEmIomkhgEUDZRnRWKM4mgAAMAG4sN96UxQJxkJAMsLOQjuQshXEpXzZYLfsD2JyAPLCABWOQAdPAwiQEYIsjN6HyZTE4n4nd9PfLFX4FUrXZBqV7QMhEmJqMJsn4WLig99xEHxATtd9is65ORqMxqKQGFJJMiHOmIJns7n6AFMdjcaB04UXQyYdA4arCzMsTjkOreV6QKBqNBm8xIAiAIRIlEwn5Ddm2AnJ52gE3mtYWiocZDOZjWfTDtQI6Iz-4zNs94Md2OL76hoThyN40Ax5BxlILr2axkAalFAEYpfGU1CRVXkND1PUPP4RhfDgh0DPlxAwBDtjkSBegYNpln1WdDT4WJ13YQxJBwQoBVAGprGgI0CO1YoymUeg2X+cYhEmGYMIWXD2HwwjNgwUjyOgTQAHdrG1YxYmwmFWBHIkwNYUwxwEqiuzPb4EXoCCDT8JSCMkUVmVZLD-jVAl4L5eTEVHAThOsWTF3UzTsO02pBJEvSmRZZBGJGEyzIQoA)

### 💻 Code

```js
// @ts-check

/**
 * @template {string | number} K
 * @template {any} T
 * @typedef {{readonly [P in K]?: T} & { readonly count: number }} Collection
 */

/**
 * @typedef {{foo: string}} Foo
 */

/**
 * @typedef { Collection<number, Foo> } FooCollection
 */

/**
 * @template {string | number} K
 * @template {any} T
 * @returns {{
 *   collection: Collection<K, T>,
 *   insert: (key: K, value: T) => void,
 * }}
 */
const makeCollection = () => {
  let count = 0;

  const getCount = () => count;

  const collection = Object.create(null, {
    count: {
      get: getCount,
      enumerable: true,
    },
  });

  /**
   * @param {K} key 
   * @param {T} value 
   */
  const insert = (key, value) => {
    // assert(!(key in collection));
    Object.defineProperty(collection, key, {
      value,
      enumerable: true,
    });
    count += 1;
  };

  return {
    collection,
    insert,
  }
}

/** @type {FooCollection | undefined} */
let foosOne;

/** @type {Collection<number, Foo> | undefined} */
let foosTwo;

function init() {
  if (!foosOne) {
    ({collection: foosOne} = makeCollection())
  }
  if (!foosTwo) {
    ({collection: foosTwo} = makeCollection())
  }
}
```

### 🙁 Actual behavior

Error on assignment to `foosOne`:
```
 Type 'Collection<number | "count", number | Foo>' is not assignable to type 'FooCollection'.
   Type 'Collection<number | "count", number | Foo>' is not assignable to type '{ readonly [x: number]: Foo; }'.
     'number' index signatures are incompatible.
       Type 'number | Foo' is not assignable to type 'Foo'.
         Type 'number' is not assignable to type 'Foo'.
```

### 🙂 Expected behavior

Same behavior when assigning to `Collection<number, Foo>` or to `FooCollection`