Skip to content

Inconsistent treatment of classes from external modules.  #4288

Description

@jdavidberger

I ran across an issue when trying to package multiple external modules into another for consumption from another API. The version of TSC here is 1.5.3.

It generates an error where it can not resolve a nested class as such; but has no issue when the class isn't nested. The generated javascript has no qualms with the generated code however; it resolves the nested class properly and the inheritance works as expected. This isn't super useful though since typescript doesn't resolve the class, so it spits out this error and many more related to the type of the derived class.

What it seems like is that even static declarations aren't resolved by typescript in such a way that it keeps the information on hand that a given lvalue is a class, and which class it is. When you do something like 'var E = B' below, for instance, it doesn't seem to recognize E as a class.

Oddly, if you do all this in the same file -- declare B as a class in main.ts -- and then assign E to the class value; you can extend E as expected.

main.ts:

import A = require('./A');
import B = require('./B');

console.log(A.B == B); 

class D1 extends B {

}

// Generates: error TS2503: Cannot find namespace 'A'.
class D2 extends A.B { } 

var E = B; 
//  error TS2304: Cannot find name 'E'.
class D3 extends E {}

A.ts

import B = require('./B');

export = {
    B: B
}

B.ts

class B {

}
export = B; 

Compile with:

tsc --noImplicitAny main.ts --module commonjs --outDir bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions