Bug: [no-loop-func] `using` / `await using` declarations are falsely flagged inside loops · Issue #12496 · typescript-eslint/typescript-eslint · GitHub
Skip to content

Bug: [no-loop-func] using / await using declarations are falsely flagged inside loops #12496

Closed

Description

@zaewc

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.
  • If I used AI assistance to prepare this issue, I have reviewed and followed the AI Contribution Policy.

Playground Link

https://typescript-eslint.io/play/#ts=6.0.3&fileType=.tsx&code=GYewTgBAFANgpgFwgSwgXggBgNwogHggGZdkBqMgSggG8AoCCAVwGdkA7AcwjDhZCZgAxnHQROiAEp8BwuFErYGEISHYskwdmIXoAfDxmCRuAPSnm7OAA8ADnCEI4AEwhwwYcBAAW7uHQBfIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1vg4%2BNoBmsJmXRRE0aB2iRwYAL4h5QA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

for (let i = 0; i < 3; i++) {
  using resource = getResource();
  const fn = () => resource; // unexpected error here
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-loop-func": "error",
  },
};

tsconfig

n/a

Expected Result

no error

resource is a using declaration, so each loop iteration gets a fresh binding, and the closure can safely capture it

Actual Result

Function declared in a loop contains unsafe references to variable(s) 'resource'.

Additional Info

No response

Activity

  1. added
    bugSomething isn't working
    package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
    triageWaiting for team members to take a look
    on Jul 6, 2026
  2. zaewc commented on Jul 6, 2026

    @zaewc
    ContributorAuthor

    I think the cause is that the extension currently only casing const

  3. kirkwaiblinger commented on Jul 6, 2026

    @kirkwaiblinger
    Member

    I can reproduce this, and, yes, without having thought too hard, it seems that the using declarations probably should be treated the same as the const declarations. But what does the base rule do here? The extension rule should probably just follow the same logic.

  4. zaewc commented on Jul 6, 2026

    @zaewc
    ContributorAuthor
  5. added
    accepting prsGo ahead, send a pull request that resolves this issue
    and removed
    triageWaiting for team members to take a look
    on Jul 6, 2026
  6. bradzacher commented on Jul 6, 2026

    @bradzacher
    Member

    Can we just delete the extension rule slash mark it as deprecated? Aren't all of the changes in the extension rule also on the base rule now?

  7. zaewc commented on Jul 7, 2026

    @zaewc
    ContributorAuthor

    Yeah, looks that way. I ran our full test suite against the base rule and everything passes. The only extra thing we had was the isTypeReference check, but the base rule handles those cases fine now without it.

  8. zaewc commented on Jul 7, 2026

    @zaewc
    ContributorAuthor

    Sorry, I accidentally closed this issue and I don’t have permission to reopen it 😰

  9. kirkwaiblinger commented on Jul 7, 2026

    @kirkwaiblinger
    Member

    Deprecate, yes, but can't remove it until the minimum supported ESLint version is raised

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions