Skip to content

Merged external modules break protected member access checking #6731

Closed
@masaeedu

Description

@masaeedu

Having some difficulty utilizing the external module augmentations feature merged in #6213. Here is a test case to demonstrate the problem:

// a.ts
export class A {
    protected protected: any;

    public setProtected(val: any) {
        this.protected = val;
    }
}
// b.ts
import {A} from './a'; // Only here to make b.ts an external module

declare module "./a" {
    interface A { }
}

This results in the following error:

a.ts(5,9): error TS2446: Property 'protected' is protected and only accessible through an instance of class 'A'.

It looks like the problem is that checkClassPropertyAccess in checker.ts ends up obtaining the merged interface as the enclosing class of the property access, rather than the actual enclosing class, then tries to ensure that this interface is derived from the class which declares the property, which isn't the case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions