Skip to content

explicitly disallow using in ambient contexts #61781

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

Merged
merged 1 commit into from
Jun 6, 2025

Conversation

Renegade334
Copy link
Contributor

@Renegade334 Renegade334 commented May 29, 2025

Since it first supported ERM, the compiler has shunned ambient using: declare [await] using is invalid, and variables appearing in the declaration emit are converted to const.

However, there is a blind spot in the checker, and that is when a variable declaration occurs in already-ambient context:

declare using a: null; // error
declare global {
    using b: null; // not an error
}
namespace N {
    export using c = null; // error
    export declare using d: null; // error
}
declare namespace N {
    using e: null; // not an error
}

Technically this doesn't apply to await using, as the checker will already complain about an invalid await context, but this PR adds errors on both for consistency.

Closes #61752.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label May 29, 2025
@Renegade334 Renegade334 marked this pull request as ready for review May 29, 2025 10:52
@jakebailey jakebailey merged commit 1e24945 into microsoft:main Jun 6, 2025
32 checks passed
@Renegade334 Renegade334 deleted the disallow-ambient-using branch June 6, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

declare namespace { using ... } generates incorrect dts
3 participants