Skip to content

docs(eslint-plugin): add info about allowDirectConstAssertionInArrowFunctions option #2586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/eslint-plugin/docs/rules/explicit-function-return-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type Options = {
allowTypedFunctionExpressions?: boolean;
// if true, functions immediately returning another function expression will not be checked
allowHigherOrderFunctions?: boolean;
// if true, arrow functions immediately returning a `as const` value will not be checked
allowDirectConstAssertionInArrowFunctions?: boolean;
// if true, concise arrow functions that start with the void keyword will not be checked
allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean;
};
Expand All @@ -77,6 +79,7 @@ const defaults = {
allowExpressions: false,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
allowDirectConstAssertionInArrowFunctions: true,
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
};
```
Expand Down Expand Up @@ -201,6 +204,22 @@ function fn() {
}
```

### `allowDirectConstAssertionInArrowFunctions`

Examples of **incorrect** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`:

```ts
const func = (value: number) => ({ type: 'X', value } as any);
const func = (value: number) => ({ type: 'X', value } as Action);
```

Examples of **correct** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`:

```ts
const func = (value: number) => ({ foo: 'bar', value } as const);
const func = () => x as const;
```

### `allowConciseArrowFunctionExpressionsStartingWithVoid`

Examples of **incorrect** code for this rule with `{ allowConciseArrowFunctionExpressionsStartingWithVoid: true }`:
Expand Down