persona-community-5/.pnpm-store/v3/files/e6/b416e0f720d0d9580ff1db3ced3e42b1d26b59ffadc5ecaff387ad693d8e7f0168a5f2d0a67050e25a971c48cd6520d5098685ec48aaf9d17521608283a203
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

94 lines
2.1 KiB
Plaintext

---
description: 'Disallow the use of variables before they are defined.'
---
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-use-before-define** for documentation.
This rule extends the base [`eslint/no-use-before-define`](https://eslint.org/docs/rules/no-use-before-define) rule.
It adds support for `type`, `interface` and `enum` declarations.
## Options
This rule adds the following options:
```ts
interface Options extends BaseNoUseBeforeDefineOptions {
enums?: boolean;
typedefs?: boolean;
ignoreTypeReferences?: boolean;
}
const defaultOptions: Options = {
...baseNoUseBeforeDefineDefaultOptions,
enums: true,
typedefs: true,
ignoreTypeReferences: true,
};
```
### `enums`
If this is `true`, this rule warns every reference to a enum before the enum declaration.
If this is `false`, this rule will ignore references to enums, when the reference is in a child scope.
Examples of code for the `{ "enums": true }` option:
<Tabs>
<TabItem value="❌ Incorrect">
```ts option='{ "enums": true }'
const x = Foo.FOO;
enum Foo {
FOO,
}
```
</TabItem>
<TabItem value="✅ Correct">
```ts option='{ "enums": false }'
function foo() {
return Foo.FOO;
}
enum Foo {
FOO,
}
```
</TabItem>
</Tabs>
### `typedefs`
If this is `true`, this rule warns every reference to a type before the type declaration.
If this is `false`, this rule will ignore references to types.
Examples of **correct** code for the `{ "typedefs": false }` option:
```ts option='{ "typedefs": false }' showPlaygroundButton
let myVar: StringOrNumber;
type StringOrNumber = string | number;
```
### `ignoreTypeReferences`
If this is `true`, this rule ignores all type references, such as in type annotations and assertions.
If this is `false`, this will will check all type references.
Examples of **correct** code for the `{ "ignoreTypeReferences": true }` option:
```ts option='{ "ignoreTypeReferences": true }' showPlaygroundButton
let var1: StringOrNumber;
type StringOrNumber = string | number;
let var2: Enum;
enum Enum {}
```