Skip to content

Commit 3721a2d

Browse files
authored
[Release-2.0] Fix 9782: do not report blocked-scope-used-before-declaration error in ambient context (#9789)
* Do not report block-scoped-used-before-declaration in ambient context * Add tests and baselines
1 parent 2aed1c8 commit 3721a2d

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ namespace ts {
976976

977977
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
978978

979-
if (!isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
979+
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
980980
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
981981
}
982982
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/test.d.ts ===
2+
3+
declare var S: typeof A; // no error
4+
>S : Symbol(S, Decl(test.d.ts, 1, 11))
5+
>A : Symbol(A, Decl(test.d.ts, 2, 13))
6+
7+
declare const A: number;
8+
>A : Symbol(A, Decl(test.d.ts, 2, 13))
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/test.d.ts ===
2+
3+
declare var S: typeof A; // no error
4+
>S : number
5+
>A : number
6+
7+
declare const A: number;
8+
>A : number
9+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @filename: test.d.ts
2+
3+
declare var S: typeof A; // no error
4+
declare const A: number;

0 commit comments

Comments
 (0)