persona-community-5/.pnpm-store/v3/files/9b/d9bc984e8e536f5dd64e2db21d8be98fc7f65be3889b7ee336492d44a48f91dc7b041d2bf55de26070476bfb8c389d2c9146549f8a38919484b55a7c6112ec
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

64 lines
1.9 KiB
Plaintext

---
description: 'Disallow using the unsafe built-in Function type.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-unsafe-function-type** for documentation.
TypeScript's built-in `Function` type allows being called with any number of arguments and returns type `any`.
`Function` also allows classes or plain objects that happen to possess all properties of the `Function` class.
It's generally better to specify function parameters and return types with the function type syntax.
"Catch-all" function types include:
- `() => void`: a function that has no parameters and whose return is ignored
- `(...args: never) => unknown`: a "top type" for functions that can be assigned any function type, but can't be called
Examples of code for this rule:
<Tabs>
<TabItem value="❌ Incorrect">
```ts
let noParametersOrReturn: Function;
noParametersOrReturn = () => {};
let stringToNumber: Function;
stringToNumber = (text: string) => text.length;
let identity: Function;
identity = value => value;
```
</TabItem>
<TabItem value="✅ Correct">
```ts
let noParametersOrReturn: () => void;
noParametersOrReturn = () => {};
let stringToNumber: (text: string) => number;
stringToNumber = text => text.length;
let identity: <T>(value: T) => T;
identity = value => value;
```
</TabItem>
</Tabs>
## When Not To Use It
If your project is still onboarding to TypeScript, it might be difficult to fully replace all unsafe `Function` types with more precise function types.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
## Related To
- [`no-empty-object-type`](./no-empty-object-type.mdx)
- [`ban-types`](./ban-types.mdx)
- [`no-wrapper-object-types`](./no-wrapper-object-types.mdx)