Repository: TypeScript
Issue: tsc fails with TypeError when I specify rootDirs:null with composite:true in an extended tsconfig
Labels: Bug,Help Wanted

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

tsconfig extend rootDirs with null Cannot read property length of undefined composite
<!--
  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

I encountered it at `typescript@4.1.3` and also reproduced in the latest `v4.2.2`

From https://github.com/microsoft/TypeScript/pull/18058 I assume overriding extended fields that you want to unset should be possible with `null`.

And it does apparently work ok unles you specify `"composite": true`.
<!-- 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 the behavior in every version I tried, and I reviewed the FAQ for entries about [tsconfig.json Behavior](https://github.com/Microsoft/TypeScript/wiki/FAQ#tsconfigjson-behavior) (no mentions of "extend", "rootDirs", "composite" there)

### ⏯ 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.
-->
It's about tsconfig, not about language itself, don't see an option to modify tsconfig in the playground, so here is a minimal reproduction repo:

https://github.com/klesun-productions/tsconfig-src-roots-null-bug-example 

### 💻 Code

<sub>tsconfig-base.json</sub>
```json
{
  "compilerOptions": {
    "rootDirs": ["src", "test"]
  }
}
```

<sub>tsconfig.json</sub>
```json
{
  "extends": "./tsconfig-base.json",
  "compilerOptions": {
    "composite": true,

    "rootDirs": null,
    "rootDir": "src"
  }
}
```
<!-- Please post the relevant code sample here as well-->


### 🙁 Actual behavior

`npm run tsc` in the [demo project](https://github.com/klesun-productions/tsconfig-src-roots-null-bug-example) results in following stack trace:
```
klesun@kunkka:~/gits/tsconfig-src-roots-null-bug-example$ npm run tsc

> tsconfig-src-roots-null-bug-example@1.0.0 tsc /home/klesun/gits/tsconfig-src-roots-null-bug-example
> tsc

/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90526
                if (option.element.isFilePath && values.length) {
                                                        ^

TypeError: Cannot read property 'length' of undefined
    at convertToReusableCompilerOptionValue (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90526:57)
    at convertToReusableCompilerOptions (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90514:32)
    at getProgramBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90452:22)
    at Object.newProgram.getProgramBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90606:63)
    at Object.getProgramBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:87903:98)
    at emitBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:82111:32)
    at emitSourceFileOrBundle (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:82083:13)
    at forEachEmittedFile (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:81828:28)
    at Object.emitFiles (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:82057:9)
    at Object.emitBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:87913:33)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tsconfig-src-roots-null-bug-example@1.0.0 tsc: `tsc`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the tsconfig-src-roots-null-bug-example@1.0.0 tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/klesun/.npm/_logs/2021-03-03T15_12_47_873Z-debug.log
```
<!-- What happened, and why it was wrong -->

### 🙂 Expected behavior

Either validation of tsconfig fields should yield a meaningful error (like it does if you specify `123` as `rootDirs` value for example `error TS5024: Compiler option 'rootDirs' requires a value of type Array.`), or it should work like described in https://github.com/microsoft/TypeScript/pull/18058 - treat `null` as removal of this field from the inherited config object.

Currently using `"rootDirs": []` workaround seems to be an equivalent of this field to be not set.

Blind guess, but could it be that somewhere in the tsc implementation you are assuming that if config object has the key then this key can't be `undefined`?
<!-- What you expected to happen instead, and why -->