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

Unexported types from "global files" visible with isolatedModules enabled #18504

Closed
davetemplin opened this issue Sep 15, 2017 · 3 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@davetemplin
Copy link

davetemplin commented Sep 15, 2017

TypeScript Version: 2.4.2

tsconfig.json

{
  "compilerOptions": {    
    "isolatedModules": true
  }
}

a.ts

import {b1} from './b';
console.log(b1()); // NO ERROR (as expected)
console.log(b2()); // ERROR (as expected)
console.log(c1()); // NO ERROR (an error is expected here)

b.ts

export function b1() {
    return 'b1';
}

function b2() {
    return 'b2';
}

c.ts

function c1() {
    return 'c1';
}

Expected behavior:
Referring to c1 from a.ts should be an error.

Actual behavior:
No error regarding c1 in a.ts.

Comment
From the description of --isolatedModules "transpile each file as a separate module" I do not expect types from any file to be visible that I haven't explicitly imported (unless they're coming in through compilerOptions.types or something like that). I get it with --isolatedModules the disposition of c1.ts is basically completely invalid. However, this behavior is very confusing particularly when migrating code bases where there might be a lot of code laying around that hasn't been refactored yet.

Is the unexpected behavior coming from the old internal module system?

@davetemplin
Copy link
Author

By the way also seeing a lot of error TS2393: Duplicate function implementation. errors caused by using the same function name in multiple files, which shouldn't be a problem if the expectation is that each file is completely isolated from each other.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 18, 2017

That is not the intention of this flag. the flag ensures that each file can be transpiled in isolation. i.e. the behavior of the emit does not depend on having full program. an example of that is const enums, whose element values are inlined at use sites.

I think you are looking for #18232 instead.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 18, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 4, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Oct 4, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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