Skip to content

Bug: typescript-estree should allow using declaration in ambient context #11244

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

Open
4 tasks done
JLHwung opened this issue May 23, 2025 · 4 comments
Open
4 tasks done
Labels
AST PRs and Issues about the AST structure bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look

Comments

@JLHwung
Copy link

JLHwung commented May 23, 2025

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.

Relevant Package

typescript-estree

Playground Link

https://typescript-eslint.io/play/#ts=5.8.3&sourceType=script&fileType=.ts&code=CYUwxgNghgTiAEA7KBbEBnADlMCBuUEAlsAPrJpY4ikEzwDeAUPPAK7pGIDm8AIgG4mAXyZA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=true

Repro Code

declare namespace valid_namespace_var {
  using D;
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
};

tsconfig

See REPL

Expected Result

Pass. The TS Playground is happy about that: https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEA7KBbEBnADlMCBuUEAlsAPrJpY4ikEzwDeAUPPAK7pGIDm8AIgG4mAXyZA

Actual Result

Error is thrown from

`'${result.kind}' declarations must be initialized.`,

Additional Info

No response

Versions

package version
@typescript-eslint/typescript-estree 8.32.1
@JLHwung JLHwung added bug Something isn't working triage Waiting for team members to take a look labels May 23, 2025
@bradzacher
Copy link
Member

Do you have a real world usecase for this? Cos honestly I'm pretty okay with this failing given its pretty nonsensical code... "just use let/const/var" is a valid workaround.

@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree awaiting response Issues waiting for a reply from the OP or another party AST PRs and Issues about the AST structure and removed triage Waiting for team members to take a look labels May 23, 2025
@kirkwaiblinger kirkwaiblinger changed the title Bug: typescript-estree should allow using declaration in ambient context Bug: typescript-estree should allow using declaration in ambient context May 23, 2025
@JLHwung
Copy link
Author

JLHwung commented May 24, 2025

Do you have a real world usecase for this? Cos honestly I'm pretty okay with this failing given its pretty nonsensical code...

I don't expect there are real world case, this feature just begins to ship very recently.

Given that tsc already accept using D in ambient context, I don't think TSESLint should reject valid TS on the parser level. And using declaration in an ambient context is not nonsensical: compared with const C, using D tells the type compiler that D must be a Disposable or nullish value: way more narrowed than const C.

Of course if tsc decides to forbid using in ambient context, then we can close this issue, but I don't think this is a decision that we should made.

@Josh-Cena
Copy link
Member

Josh-Cena commented May 24, 2025

The complication is that the parser has no way to reliably detect ambient contexts without reproducing a lot of detection logic, so traditionally to allow ambient declaration syntax we must allow them wholesale in the parser, for example uninitialized const. This obviously lets a lot of invalid AST slip through, which TS OTOH can detect due to semantic analysis, so we'd rather err on the stricter side if possible.

@bradzacher
Copy link
Member

Yeah I'm personally okay with us being incorrect here because having to detect the "ambient declaration context" is a pain and not something we do in the parser right now. Without a real-world usecase I don't personally see the motivation to build that logic in -- I don't think that academic correctness is a good enough reason.

cc @typescript-eslint/triage-team thoughts?

@bradzacher bradzacher added triage Waiting for team members to take a look and removed awaiting response Issues waiting for a reply from the OP or another party labels May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AST PRs and Issues about the AST structure bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy