Repository: TypeScript
Issue: Combination of intersection type, mapped type and generic type seem to break type checks for nested properties
Labels: Bug,Help Wanted

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms
mapped types, generic bound, nested objects

### 🕗 Version & Regression Information

We've detected this on `4.7.4`. Checking previous versions on playgrounds, last one where it worked correctly is `3.5.1`.
It is also reproducible on current nightly build.

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This changed between versions 3.5.1 and 3.6.3

### ⏯ Playground Link

[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvKEhQAYgFdixVBszwkB6ADJsoqLxDAJ9HgHMWHLhF74VefOugBZODBIRlMAHmQAPihMXAIoAG0AawgQBh4oZJB2ADMoZABdWjyklPzPVUZyYjhZKGztHgp6dnTHCB4ZejIdRuBmnnCoCAAPYHbGBC1dfTQIgAoaxwRaAKCIELRwiIBKWgA3diZVNo7pLp6mlrnY8SlZeUUrEnJgeStCJlpgaW0IJUJCAB6QFQOz0SYICTsXSMKA8djAKBgRAId5EKEwgCi0mk7GkAAkZHIoAByarkuDVElWLx8bZAA)

### 💻 Code

```ts
type BaseType = {
  select?: { id?: boolean} ,

  where: {},
}

type FullType = BaseType & {
  anything?: boolean
}

type MappedType<T> = {
  [key in keyof T]:  T[key]
}

declare function genericFunction<T extends FullType>(args: MappedType<T>): void

genericFunction({
  where: {},
  select: {
    id: true,
    // this should not pass
    shouldErrorHere: 'lalalala'
  }
})
```

### 🙁 Actual behavior

The code passes typechecks

### 🙂 Expected behavior

`shouldErrorHere` property should not be allowed in that position, since it's not defined on `typeof BaseType['select']`.  Doing any  of the following causes expected error to appear:

1. [Removing intersection type and making `FullType` a plain alias for `BaseType`](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvKEhQAYgFdixVBszwkBiKvXQAsnDCRGpgDzIAfFEy4CUANoBrCCAYeKD8QdgAzKGQAXVpI338o-BU8fEZyYjhZKDDtHgp6diCAcwgeGXoyHTzgAp4nKAgAD2BSxgQtXX00ZwAKTKKEWmtbCHs0J2cASloAN3YmVRKy6Qqq-MKej3EpWXlFUSIIUgp5A8ImWmBpbQglQkIAegeoYAl6doQJdl1GKB52YBQMCIBBnIhfH4AUWk0nY0gAEjI5FAAOQZdFwDIog7JPiTIA)
2. [Making `where` property optional in `BaseType` definition](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcILLH2F4+IvKEhQAYgFdixVBszwkB6ADJsoqLxDAJ9HgHMWHLhF74VefOugBZODBIRlMAHmQAPihMXAIoAG0AawgQBh4oZJB2ADMoZABdWjyklPzPVUZyYjhZKGztHgp6dnTHCB4ZejIdRuBmnnCoCAAPYHbGBC1dfTQIgAoaxwRaAKCIELRwiIBKWgA3diZVNo7pLp6mlrnY8SlZWgUlQhJyYAerQiZaYGltCCfCEQJOxdIwAKLSaTsaQACRkEFoAHJqii4NVEVYvHxtkA)
3. [Removing `anything` property from `FullType`](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvKEhQAYgFdixVBszwkB6ADJsKvPnXQAsnDCRGpgDzIAfFEy4CUANoA1hAgDDxQwSDsAGZQyAC6tHFBIfH4VviM5MRwslDR2jwU9OzhAOYQPDL0ZDpFwCU87lAQAB7AlYwIWrr6aB4AFLllCLQOThAuaO4eAJS0AG7sTKoVVdI1dcWlA77iUrLyiqJEEKQU8ieETLTA0toQSoSECBLsuowAotLS7NIAEjI5FAAOQ5cFwHIgk5WPizIA)
4. [Adding any non-optional property to the intersection](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvKEhQAYgFdixVBszwkB6ADJsoqLxDAJ9HgHMWHLhF5We7HgHkwwem84YlpXbh58FTx8dWgAWTgwSEZTAB5kAD4oTFwCKABtAGsIEAYeKGKQdgAzKGQAXVo6opL6yNVGcmI4WShq7R4KQPLHCB4ZejIdQYDvdKgIAA9gMcYELV19NAyACh7HBFoEpIgUtHSMgEpaADd2JlVR8elJ6aHvHdzxKVl5RSsSORgPIrIQmLRgNJtBAlIRCAgJOxdIwAKLSaTsaQACRkcigAHJukTgnB8VYonxLkA)
5. [Omitting `where` property in `genericFunction` call](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvKEhQAYgFdixVBszwkB6ADJsoqLxDAJ9HgHMWHLhF74VefOugBZODBIRlMAHmQAPihMXAIoAG0AawgQBh4oZJB2ADMoZABdWjyklPzPVUZyYjhZKGztHgp6dnTHCB4ZejIdRuBmnnCoCAAPYHbGBC1dfTQIgAoaxwRaAKCIELRwiIBKWgA3diZVNo7pLp6mlrnYwhJyYHkrQiZaYGltCCVCW4l2XUYAKLSaTsaQACRkcigAHJqnC4NVoVYvHxtkA)
6. [Passing incorrect `anything` value during the call](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvKEhQAYgFdixVBszwkB6ADJsoqLxDAJ9HgHMWHLhF74VefOugBZODBIRlMAHmQAPihMXAIoAG0AawgQBh4oZJB2ADMoZABdWjyklPzPVUZyYjhZKGztHgp6dnTHCB4ZejIdRuBmnnCoCAAPYHbGBC1dfTQIgAoaxwRaAKCIELRwiIBKWgA3diZVNo7pLp6mlrnY8SlZeUUrEnJgeStCJlpgaW0IJUJCAgJOxdIwAKLSaTsaQACRkcigAHJqii4NVEVZHnEbHYHI5aIieOxgNY2JxuDxEUo+NsgA)
7. [Changing `FullType` to `interface FullType extends BaseType`](https://www.typescriptlang.org/play?ts=4.7.2#code/C4TwDgpgBAQghgZwgFXNAvFA3gWAFBRRIA2EAxsAPwBc2UAlgCY1QBGA9u6XAHYC+UADT58hAO4ALCACcItLH2F4+IvPR7AZAMzhloAMQCuxYqkhQIAD009GCWIhRpCuAlF4hgE9QHMWHLghefBU8fFBzAFk4MEhGMwgAHmQAPihMV0IAbQBrCBAGHig8kHYtKGQAXVoK3PzKkNVGcmI4WSgtQx4KenYinwgeGXoyI27gXp5ki2tBuygjEwSUgAo2nwRaaNiIeLRklIBKWgA3diZVAaHpEbGevpXMqEkZOWxFUSIIUgp5T8ImLRgNJDBAlIRCAgJOxjIwAKLSaTsaQACVetAA5K1sXBWhjPqE+IcgA)