You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `allow` option is an array of identifier names for which shadowing is allowed. For example, `"resolve"`, `"reject"`, `"done"`, `"cb"`.
@@ -229,3 +275,89 @@ const y = (y => y)()
229
275
:::
230
276
231
277
The rationale for callback functions is the assumption that they will be called during the initialization, so that at the time when the shadowing variable will be used, the shadowed variable has not yet been initialized.
278
+
279
+
### ignoreTypeValueShadow
280
+
281
+
Whether to ignore types named the same as a variable. Default: `true`.
282
+
283
+
This is generally safe because you cannot use variables in type locations without a typeof operator, so there's little risk of confusion.
284
+
285
+
Examples of **correct** code with `{ "ignoreTypeValueShadow": true }`:
**Note:** Shadowing specifically refers to two identical identifiers that are in different, nested scopes. This is different from redeclaration, which is when two identical identifiers are in the same scope. Redeclaration is covered by the [`no-redeclare`](/rules/no-redeclare) rule instead.
306
+
307
+
308
+
### ignoreFunctionTypeParameterNameValueShadow
309
+
310
+
Whether to ignore function parameters named the same as a variable. Default: `true`.
311
+
312
+
Each of a function type's arguments creates a value variable within the scope of the function type. This is done so that you can reference the type later using the typeof operator:
313
+
314
+
```ts
315
+
typeFunc= (test:string) =>typeoftest;
316
+
317
+
declareconst fn:Func;
318
+
const result =fn('str'); // typeof result === string
319
+
```
320
+
321
+
This means that function type arguments shadow value variable names in parent scopes:
322
+
323
+
```ts
324
+
let test =1;
325
+
typeTestType=typeoftest; // === number
326
+
typeFunc= (test:string) =>typeoftest; // this "test" references the argument, not the variable
327
+
328
+
declareconst fn:Func;
329
+
const result =fn('str'); // typeof result === string
330
+
```
331
+
332
+
If you do not use the `typeof` operator in a function type return type position, you can safely turn this option on.
333
+
334
+
Examples of **correct** code with `{ "ignoreFunctionTypeParameterNameValueShadow": true }`:
### Why does the rule report on enum members that share the same name as a variable in a parent scope?
348
+
349
+
This isn't a bug — the rule is working exactly as intended! The report is correct because of a lesser-known aspect of enums: enum members introduce a variable within the enum's own scope, allowing them to be referenced without needing a qualifier.
350
+
351
+
Here's a simple example to explain:
352
+
353
+
```ts
354
+
const A =2;
355
+
enumTest {
356
+
A=1,
357
+
B=A,
358
+
}
359
+
360
+
console.log(Test.B); // what should be logged?
361
+
```
362
+
363
+
At first glance, you might think it should log `2`, because the outer variable A's value is `2`. However, it actually logs `1`, the value of `Test.A`. This happens because inside the enum `B = A` is treated as `B = Test.A`. Due to this behavior, the enum member has shadowed the outer variable declaration.
0 commit comments