A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://typescript-eslint.io/rules/no-unsafe-function-type below:

no-unsafe-function-type | typescript-eslint

no-unsafe-function-type

Disallow using the unsafe built-in Function type.

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:

Examples of code for this rule:

let noParametersOrReturn: Function;
noParametersOrReturn = () => {};

let stringToNumber: Function;
stringToNumber = (text: string) => text.length;

let identity: Function;
identity = value => value;
Open in Playground
let noParametersOrReturn: () => void;
noParametersOrReturn = () => {};

let stringToNumber: (text: string) => number;
stringToNumber = text => text.length;

let identity: <T>(value: T) => T;
identity = value => value;
Open in Playground

eslint.config.mjs

export default tseslint.config({
rules: {
"@typescript-eslint/no-unsafe-function-type": "error"
}
});

.eslintrc.cjs

module.exports = {
"rules": {
"@typescript-eslint/no-unsafe-function-type": "error"
}
};

Try this rule in the playground ↗

Options

This rule is not configurable.

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 for those specific situations instead of completely disabling this rule.

Resources

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4