Skip to content

Commit c3479c0

Browse files
authored
isolated-functions: Ignore TypeScript types (#2822)
1 parent 609d487 commit c3479c0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

rules/isolated-functions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ const create = context => {
5353
// `through`: "The array of references which could not be resolved in this scope" https://eslint.org/docs/latest/extend/scope-manager-interface#scope-interface
5454
for (const reference of nodeScope.through) {
5555
const {identifier} = reference;
56+
57+
if (identifier.parent.type === 'TSTypeReference' || identifier.parent.type === 'TSTypeQuery') {
58+
continue;
59+
}
60+
5661
if (identifier.name in allowedGlobals && allowedGlobals[identifier.name] !== 'off') {
5762
if (reference.isReadOnly()) {
5863
continue;

test/isolated-functions.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import outdent from 'outdent';
2-
import {getTester} from './utils/test.js';
2+
import {getTester, parsers} from './utils/test.js';
33

44
const {test} = getTester(import.meta);
55

@@ -77,6 +77,25 @@ test({
7777
});
7878
`,
7979
},
80+
{
81+
name: 'typescript types are allowed to be out-of-scope',
82+
languageOptions: {
83+
parser: parsers.typescript,
84+
},
85+
code: outdent`
86+
const a = 1;
87+
type MyType = { foo: string };
88+
makeSynchronous(() => {
89+
const b: typeof a = 1;
90+
const f = <T extends MyType>(t: T) => t;
91+
let myType: MyType = { foo: 'bar' };
92+
myType = { foo: 'bar' } as MyType;
93+
myType = { foo: 'bar' } as const;
94+
myType = { foo: 'baz' } satisfies MyType;
95+
type X = typeof myType extends MyType ? true : false;
96+
});
97+
`,
98+
},
8099
],
81100
/** @type {import('eslint').RuleTester.InvalidTestCase[]} */
82101
invalid: [

0 commit comments

Comments
 (0)