Allow references to uninitialized ambient properties (#36112)

Previously these were incorrectly treated just like normal properties:

```ts
class Parent {
    a: any;
    constructor(arg: any) {
        this.a = arg;
    }
}
class Child extends Parent {
    declare a: number;
    constructor(arg: number) {
        super(arg);
        console.log(this.a);  // Property 'a' is used before being assigned. (2565)
    }
}
```

Fixes #35327
This commit is contained in:
Nathan Shively-Sanders
2020-01-10 10:50:05 -08:00
committed by GitHub
parent 357f715382
commit 13cddae3f7
6 changed files with 147 additions and 1 deletions

View File

@@ -23298,7 +23298,7 @@ namespace ts {
const declaration = prop && prop.valueDeclaration;
if (declaration && isInstancePropertyWithoutInitializer(declaration)) {
const flowContainer = getControlFlowContainer(node);
if (flowContainer.kind === SyntaxKind.Constructor && flowContainer.parent === declaration.parent) {
if (flowContainer.kind === SyntaxKind.Constructor && flowContainer.parent === declaration.parent && !(declaration.flags & NodeFlags.Ambient)) {
assumeUninitialized = true;
}
}