Skip to content

Commit 33f362a

Browse files
authored
Don’t issue used-before-initialization errors in declaration files (microsoft#32579)
1 parent 73bef22 commit 33f362a

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

src/compiler/checker.ts

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

2070120701
function checkPropertyNotUsedBeforeDeclaration(prop: Symbol, node: PropertyAccessExpression | QualifiedName, right: Identifier): void {
2070220702
const { valueDeclaration } = prop;
20703-
if (!valueDeclaration) {
20703+
if (!valueDeclaration || getSourceFileOfNode(node).isDeclarationFile) {
2070420704
return;
2070520705
}
2070620706

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/declaration.d.ts ===
2+
export declare class ClassWithSymbols {
3+
>ClassWithSymbols : Symbol(ClassWithSymbols, Decl(declaration.d.ts, 0, 0))
4+
5+
public readonly [Namespace.locallyExportedCustomSymbol]: string;
6+
>[Namespace.locallyExportedCustomSymbol] : Symbol(ClassWithSymbols[Namespace.locallyExportedCustomSymbol], Decl(declaration.d.ts, 0, 39))
7+
>Namespace.locallyExportedCustomSymbol : Symbol(Namespace.locallyExportedCustomSymbol, Decl(declaration.d.ts, 5, 14))
8+
>Namespace : Symbol(Namespace, Decl(declaration.d.ts, 3, 1))
9+
>locallyExportedCustomSymbol : Symbol(Namespace.locallyExportedCustomSymbol, Decl(declaration.d.ts, 5, 14))
10+
11+
public [Namespace.fullyExportedCustomSymbol](): void;
12+
>[Namespace.fullyExportedCustomSymbol] : Symbol(ClassWithSymbols[Namespace.fullyExportedCustomSymbol], Decl(declaration.d.ts, 1, 66))
13+
>Namespace.fullyExportedCustomSymbol : Symbol(Namespace.fullyExportedCustomSymbol, Decl(declaration.d.ts, 6, 14))
14+
>Namespace : Symbol(Namespace, Decl(declaration.d.ts, 3, 1))
15+
>fullyExportedCustomSymbol : Symbol(Namespace.fullyExportedCustomSymbol, Decl(declaration.d.ts, 6, 14))
16+
}
17+
export namespace Namespace {
18+
>Namespace : Symbol(Namespace, Decl(declaration.d.ts, 3, 1))
19+
20+
export const locallyExportedCustomSymbol: unique symbol;
21+
>locallyExportedCustomSymbol : Symbol(locallyExportedCustomSymbol, Decl(declaration.d.ts, 5, 14))
22+
23+
export const fullyExportedCustomSymbol: unique symbol;
24+
>fullyExportedCustomSymbol : Symbol(fullyExportedCustomSymbol, Decl(declaration.d.ts, 6, 14))
25+
}
26+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/declaration.d.ts ===
2+
export declare class ClassWithSymbols {
3+
>ClassWithSymbols : ClassWithSymbols
4+
5+
public readonly [Namespace.locallyExportedCustomSymbol]: string;
6+
>[Namespace.locallyExportedCustomSymbol] : string
7+
>Namespace.locallyExportedCustomSymbol : unique symbol
8+
>Namespace : typeof Namespace
9+
>locallyExportedCustomSymbol : unique symbol
10+
11+
public [Namespace.fullyExportedCustomSymbol](): void;
12+
>[Namespace.fullyExportedCustomSymbol] : () => void
13+
>Namespace.fullyExportedCustomSymbol : unique symbol
14+
>Namespace : typeof Namespace
15+
>fullyExportedCustomSymbol : unique symbol
16+
}
17+
export namespace Namespace {
18+
>Namespace : typeof Namespace
19+
20+
export const locallyExportedCustomSymbol: unique symbol;
21+
>locallyExportedCustomSymbol : unique symbol
22+
23+
export const fullyExportedCustomSymbol: unique symbol;
24+
>fullyExportedCustomSymbol : unique symbol
25+
}
26+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @filename: declaration.d.ts
2+
3+
export declare class ClassWithSymbols {
4+
public readonly [Namespace.locallyExportedCustomSymbol]: string;
5+
public [Namespace.fullyExportedCustomSymbol](): void;
6+
}
7+
export namespace Namespace {
8+
export const locallyExportedCustomSymbol: unique symbol;
9+
export const fullyExportedCustomSymbol: unique symbol;
10+
}

0 commit comments

Comments
 (0)