Repository: TypeScript
Issue: Type is not inferred in an if branch of a user-defined type guard when object is used for destructuring
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.
-->

**TypeScript Version:**  3.9.2, v4.0.0-dev.20200519 

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:** type guard, destructuring, infer, if branch

**Expected behavior:**

Code compiles with no errors and inferred type of `withoutSymbols` is `{ [key: string]: TreeNode }`

**Actual behavior:**

Fails with `Rest types may only be created from object types.` error at line:
```ts
const { [VALUE]: value, [PARAM]: param, ...withoutSymbols } = node
```
To fix this, `node` variable should be cast to `TreeNode`:
```ts
const { [VALUE]: value, [PARAM]: param, ...withoutSymbols } = node as TreeNode
``` 
It seems redundant since this line of code is in the if branch of `isRootNode` type guard already. 

**Code**
```ts
const VALUE: unique symbol = Symbol('value')
const PARAM: unique symbol = Symbol('param')

type RootTreeNode = {
  [key: string]: TreeNode
}

type TreeNode = {
  [VALUE]: string
  [PARAM]?: RootTreeNode
  [key: string]: TreeNode
}

function isRootNode(node: RootTreeNode | TreeNode): node is RootTreeNode {
    return !(VALUE in node)
}

function filterSymbolsOut(node: RootTreeNode | TreeNode): RootTreeNode {
  if (!isRootNode(node)) {
    const { [VALUE]: value, [PARAM]: param, ...withoutSymbols } = node
    return withoutSymbols
  }
  return node
}

```



<details><summary><b>Output</b></summary>

```ts
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
const VALUE = Symbol('value');
const PARAM = Symbol('param');
function isRootNode(node) {
    return !(VALUE in node);
}
function filterSymbolsOut(node) {
    if (!isRootNode(node)) {
        const _a = node, _b = VALUE, value = _a[_b], _c = PARAM, param = _a[_c], withoutSymbols = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]);
        return withoutSymbols;
    }
    return node;
}

```


</details>


<details><summary><b>Compiler Options</b></summary>

```json
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}
```


</details>

**Playground Link:** [Provided](https://www.typescriptlang.org/play/index.html#code/MYewdgzgLgBAagQQDIFUCiAuGBXMBLAR2wFMYIBPAWwCMQAbGAXhgGUra6AKAcgDcBDOiW4BKAFChIsAAoIASggCyWXIRJl29Jq01duAB34AnfpVFixUcvtJyQIKABUjxYgDkQAE1LMA3mJgYAG0Aa2JyLGgjPDAAcwBdLGdXD28xAF8LKxsYZPcvHxh-QKDEVDREsihouIDg2QVFeIB+LDsHPNTiOtDwyOqYhKSXfLTMsQAzXGAoPHAYPAh2qC7OMAK2+ycRrpgAH1ydgpEsde8FiBhlzoKiusCXKGwjMBgAQk4y9AXXs+JxcZTMAzOavCZ4OhQYhGNg0egQADy2Cgaw2Vy2N3OB0x-02HSO52KCwmME4b0Wy1WfxEIjugUCkmgRWCXwqWAEQmIABp6vIlJVDCZKDyAHRigDueCgAAsQMjYRxLultH97jBHs9XpKZXKoAr4XVMg9iE8XjBVZkgA)