Repository: TypeScript
Issue: ts-expect-error is reported as unused on rootDir error
Labels: Bug,Help Wanted,Effort: Moderate

# Bug Report

[Minimal reprod repo](https://github.com/proteriax/ts-expect-error-bug).

`ts-expect-error` cannot be used to silent a ts(6059, rootDir not containing all the files) error.

| with directive | without directive |
|:----:|:-----:|
|<img width="411" alt="Capture d’écran, le 2022-04-26 à 09 23 07" src="https://user-images.githubusercontent.com/8125011/165309695-abbaf594-55d4-44ed-bfbb-7e6faa21cb1f.png">|<img width="605" alt="Capture d’écran, le 2022-04-26 à 09 24 28" src="https://user-images.githubusercontent.com/8125011/165309943-63bb40b0-6cc5-4efd-a3a1-0691fc5a8f37.png"> |

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms
ts-expect-error, rootDir, 6059

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->

### 🕗 Version & Regression Information

TypeScript 4.6.3.

<!-- 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 is a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because this involves tsconfig.json.

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
https://github.com/proteriax/ts-expect-error-bug

### 💻 Code

See reprod repo above.

<!-- Please post the relevant code sample here as well-->
```ts
// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.
```

### 🙁 Actual behavior

The error goes away with a `// @ts-expect-error` above it.

<!-- What happened, and why it was wrong -->

### 🙂 Expected behavior

See screenshot above. If you have the directive, TypeScript thinks it’s useless; if you don’t, TypeScript will give you an error.

<!-- What you expected to happen instead, and why -->