Skip to content

Unexpected type reference between divided modules #10625

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

Closed
vvakame opened this issue Aug 31, 2016 · 1 comment
Closed

Unexpected type reference between divided modules #10625

vvakame opened this issue Aug 31, 2016 · 1 comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@vvakame
Copy link
Contributor

vvakame commented Aug 31, 2016

TypeScript Version: 2.0.2

Code

sampleA.ts

{
    // local types
    type Data = string | boolean;
    let obj: Data = true;
    console.log(obj);
}
export { }

sampleB.ts

let v = "str" || true;

export { v }

tsconfig.json

{
    "compilerOptions": {
        "declaration": true,
        "skipDefaultLibCheck": true
    },
    "include": [
        "sample*.ts"
    ]
}

This is minimal settings.
When "declaration": true and "skipDefaultLibCheck": true, this issue is occured.

Expected behavior:

We can compile this code.

Actual behavior:

$ tsc -v
Version 2.0.2
$ tsc -p ./
sampleB.ts(1,5): error TS4023: Exported variable 'v' has or is using name 'Data' from external module "/private/tmp/hogehogehoge/sampleA" but cannot be named.
@vladima
Copy link
Contributor

vladima commented Aug 31, 2016

at glance root cause of the issue is caching of union types: type of Data in sampleA.ts is string | boolean and it is the same with type of v in sampleB.ts. However type in the first case has associated alias which is not visible if the same type is reused in different context.

Why error does not repro without skipDefaultLibCheck - I guess some declaration in lib.d.ts has the same type. This type will be put in the cache and used for both sampleA.ts and sampleB.ts will

// CC @ahejlsberg

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants