Unexpected type reference between divided modules #10625
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Activity
vladima commentedon Aug 31, 2016
at glance root cause of the issue is caching of union types: type of
DatainsampleA.tsisstring | booleanand it is the same with type ofvinsampleB.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 inlib.d.tshas the same type. This type will be put in the cache and used for bothsampleA.tsandsampleB.tswill// CC Anders Hejlsberg (@ahejlsberg)