Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Cannot find namespace ...' for type declarations using default-exported module import #4395

Closed
pcan opened this issue Aug 21, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@pcan
Copy link
Contributor

pcan commented Aug 21, 2015

I found a strange behaviour when importing a default-exported module from file1 and using it for variable/parameter/return value/whatever... type declarations in file2. Please note that the imported namespace is still visible and works correctly when I use it for variable definitions (e.g. invoking class constructor with new). See the code below:

file1.ts

export module a {
    export module b {
        export class MyClass {
            x: number = 10;
        }
    }
}

export default a.b;

file2.ts

import y from './file1';

function fn(): y.MyClass {      //warning here: Cannot find namespace 'y'.
    return new y.MyClass();     //it works here, no compiler warning
}

var a = fn();                   //works fine
var b: y.MyClass = fn();        //warning here: Cannot find namespace 'y'.

function fn2(i: y.MyClass) {    //warning here: Cannot find namespace 'y'.
}

Instead, for class expression (export default class {... in file1.ts) it works fine, both for type declarations and variable definitions.

@pcan pcan changed the title 'Cannot find namespace ...' for type declarations using default-exported import 'Cannot find namespace ...' for type declarations using default-exported module import Aug 21, 2015
@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 21, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Aug 21, 2015

looks like a duplicate of #4325.

The problem is the compiler will export all meanings of a name, iff it is an identifier and not a dotted name.. i.e:

export default a.b; // exports only the value a.b, no type or namespace

export default b; // exports all meanings of b, value, type and namespace

i agree that this is a wrong behavior. for now, use an alias to work around the issue:

export module a {
    export module b {
        export class MyClass {
            x: number = 10;
        }
    }
}

import _b = a.b;
export default _b;

@pcan
Copy link
Contributor Author

pcan commented Aug 21, 2015

Ok, thanks.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants