# Compiler Checks For Unused Params And Variables

There are a number of linter-esque checks that you can tell the TypeScript compiler to make when it is checking your code. There are two that prevent values from going unused: one for parameters and the other for variables.

The [`noUnusedLocals`](https://www.typescriptlang.org/tsconfig#noUnusedLocals) config, which defaults to `false`, can be set to `true`. This will cause the compiler to fail if a locally declared variable goes unused.

```typescript
function printItem(item: any, index: number) {
  const indexedItem = `${index}: ${item}`;
  //    ^^^ 'indexedItem' is declared but its value is never read.

  console.log(item);
}
```

The [`noUnusedParameters`](https://www.typescriptlang.org/tsconfig#noUnusedParameters) config, which also defaults to `false`, can be set to `true`. This will cause the compiler to fail if a function param goes unused.

Fixing the previous error could then result in this one.

```typescript
function printItem(item: any, index: number) {
  //                          ^^^
  // 'index' is declared but its value is never read.

  console.log(item);
}
```

Here is what the `tsconfig.json` would look like:

```json
{
  "compilerOptions": {
    "noUnusedLocals": true,
    "noUnusedParameters": true,
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/typescript/compiler-checks-for-unused-params-and-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
