# @typescript-eslint/explicit-module-boundary-types

> Require parameter and return types on exported functions and the methods of exported classes

If TypeScript infers an exported function's return type from its body, a change inside the function changes the type that every importing file sees. Nobody notices while making the edit, and the errors show up in those other files.

This rule checks exported functions and the non-private methods of exported classes. They need a return type and a type for every parameter, and that type can't be `any`. A parameter with a default value is fine without a type. Functions that aren't exported aren't checked.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/explicit-module-boundary-types" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/explicit-module-boundary-types" = ["error", {
  allowArgumentsExplicitlyTypedAsAny = false,
  allowTypedFunctionExpressions = true,
  allowHigherOrderFunctions = true,
  allowDirectConstAssertionInArrowFunctions = true,
  allowOverloadFunctions = false,
  allowedNames = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
export function parsePrice(text) {
  return Number(text.replace("$", ""));
}

export function log(value: any): void {
  console.log(value);
}
```

An export further down the file counts too:

{/* bad */}
```ts
const isEmpty = (items: string[]) => items.length === 0;

export { isEmpty };
```

Not reported:

{/* good */}
```ts
export function parsePrice(text: string): number {
  return Number(strip(text));
}

export function log(value: unknown, level = "info"): void {
  console.log(level, value);
}

function strip(text: string) {
  return text.replace("$", "");
}

export class Cart {
  private count() {
    return 0;
  }
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowArgumentsExplicitlyTypedAsAny` | `false` | Allow a parameter that's written as `any`. |
| `allowTypedFunctionExpressions` | `true` | Allow a function expression that gets its type from a typed variable or property, or from an `as`. |
| `allowHigherOrderFunctions` | `true` | Allow a function that returns another function right away to go without a return type. The inner function is still checked. |
| `allowDirectConstAssertionInArrowFunctions` | `true` | Allow `() => value as const` to go without a return type. |
| `allowOverloadFunctions` | `false` | Skip the implementation of a function that has overload signatures. |
| `allowedNames` | `[]` | Names of functions and methods that are never reported. |

With `allowTypedFunctionExpressions`, the type on the variable is enough:

{/* good */}
```ts
type Check = (items: string[]) => boolean;

export const isEmpty: Check = items => items.length === 0;
```

{/* bad {"options": [{"allowTypedFunctionExpressions": false}]} */}
```ts
type Check = (items: string[]) => boolean;

export const isEmpty: Check = items => items.length === 0;
```

With `allowHigherOrderFunctions`, only the inner function needs a return type:

{/* good */}
```ts
export const multiplyBy = (factor: number) => (value: number): number => value * factor;
```

With `allowOverloadFunctions`, callers only see the overload signatures:

{/* good {"options": [{"allowOverloadFunctions": true}]} */}
```ts
export function double(value: number): number;
export function double(value: string): string;
export function double(value: number | string) {
  return typeof value === "number" ? value * 2 : value + value;
}
```

{/* bad */}
```ts
export function double(value: number): number;
export function double(value: string): string;
export function double(value: number | string) {
  return typeof value === "number" ? value * 2 : value + value;
}
```
