Repository: TypeScript
Issue: Regression: Type T[K] as an array when sliced loses its type
Labels: Bug

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!

Please help us by doing the following steps before logging an issue:
  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ

Please fill in the *entire* template below.
-->

<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
**TypeScript Version:**  3.4.5

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:**
array property generics
**Code**

```ts
export function GetArrayProp<U, K extends string, T extends Record<K, U[]>>(
  state: T,
  prop: K,
) {
  //good
  let x1: T[K] = state[prop];
  //good
  let x2: U[] = state[prop];
  //good
  let x3: U[] = state[prop].slice(0);
  //error
  let x4: T[K] = state[prop].slice(0);
}
```
While you can argue that U[]  isn't necessarily assignable to type T[K]. Look at the following code.
It's hard to see how TypeFromArray<T[K]>[]'s type should be any different than T[K]

```ts
export type TypeFromArray<T> = T extends (infer R)[] ? R : never;

export function GetArrayProp<K extends string, T extends Record<K, Array<TypeFromArray<T[K]>>>>(
  obj: T,
  prop: K,
) {
  //good
  let x1: T[K] = obj[prop];
  //good
  let x2 = obj[prop].slice(0);
  //error Type 'TypeFromArray<T[K]>[]' is not assignable to type 'T[K]'.
  let x3: T[K] = obj[prop].slice(0);
}
```

**Expected behavior:**

No errors.
T[K] and U[] should be assignable to each other.
state[prop].slice(0) should be of the same type as state[prop]
TypeFromArray<T[K]>[]'s type should be not be any different than T[K]

This code works in version 3.2.4 but stopped working in 3.3.1

**Actual behavior:**

Error Type 'U[]' is not assignable to type 'T[K]'.
Error Type 'TypeFromArray<T[K]>[]' is not assignable to type 'T[K]'

**Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior -->

[Playground Link](https://www.typescriptlang.org/play/index.html#src=export%20function%20GetArrayProp%3CU%2C%20K%20extends%20string%2C%20T%20extends%20Record%3CK%2C%20U%5B%5D%3E%3E(%0D%0A%20%20obj%3A%20T%2C%0D%0A%20%20prop%3A%20K%2C%0D%0A)%20%7B%0D%0A%20%20%2F%2Fgood%0D%0A%20%20let%20x1%3A%20T%5BK%5D%20%3D%20obj%5Bprop%5D%3B%0D%0A%20%20%2F%2Fgood%0D%0A%20%20let%20x2%3A%20U%5B%5D%20%3D%20obj%5Bprop%5D%3B%0D%0A%20%20%2F%2Fgood%0D%0A%20%20let%20x3%3A%20U%5B%5D%20%3D%20obj%5Bprop%5D.slice(0)%3B%0D%0A%20%20%2F%2Ferror%0D%0A%20%20let%20x4%3A%20T%5BK%5D%20%3D%20obj%5Bprop%5D.slice(0)%3B%0D%0A%7D)



My main goal is to be able to pluck array properties and modify the arrays without losing the type T[K]
The code above is simplified to show how TS is behaving.
See my use case below.

It's hard to see how TypeFromArray<T[K]>[]'s type should be any different than T[K]
The code below used to work when using 3.2.4

```ts

import { EntityState, EntityAdapter } from '@ngrx/entity';
import { Action } from '@ngrx/store';

export type TypeFromArray<T> = T extends (infer R)[] ? R : never;

type Selector<T> = (s: T) => boolean;


function ModifyEntityFromState<T>(entityId: number, state: EntityState<T>, callBack:  (acnt: T) => void): T {
  const t = state.entities[entityId];
  const acnt = JSON.parse(JSON.stringify(t)) as T;
  callBack(acnt);
  return acnt;
}


export function ModifyPropertyFromState<T, K extends keyof T>(
  entityId: number,
  state: EntityState<T>,
  prop: K,
  callBack: (a: T[K]) => T[K],
): T {
  return ModifyEntityFromState( entityId, state, (acnt) => {
    acnt[prop] = callBack( acnt[prop]  );
  });
}


export function EditArrayFromState<
T extends Record<K, Array<TypeFromArray<T[K]>>>,
K extends keyof T,
U extends TypeFromArray<T[K]>
>(
  entityId: number, state: EntityState<T>, prop: K,
  selector: Selector<U>,
  modified: U
): T {
  return ModifyPropertyFromState( entityId, state, prop, (a) => {
//Argument of type '(a: T[K]) => TypeFromArray<T[K]>[]' is not assignable to parameter of type '(a: T[K]) => T[K]'.
//  Type 'TypeFromArray<T[K]>[]' is not assignable to type 'T[K]'
    const idx = a.findIndex(selector);
    return  [
      ...a.slice(0, idx),
      ...a.slice(idx + 1),
      modified
    ];
  });
}



```