Skip to content

Suggestion: Add a flag to forbid use of global symbols #21318

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
shivanshu3 opened this issue Jan 20, 2018 · 2 comments
Closed

Suggestion: Add a flag to forbid use of global symbols #21318

shivanshu3 opened this issue Jan 20, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@shivanshu3
Copy link
Member

The following code compiles in TypeScript but running the compiled output under Node.js results in an error:

> node foo.js
> ReferenceError: Person is not defined

Contents of foo.ts:

let a: Person = new Person();

Contents of bar.ts:

class Person {}

Contents of tsconfig.json:

{
	"compilerOptions": {
		"target": "es5",
		"module": "commonjs",
		"strict": true
	}
}

My understanding is that since bar.ts doesn't have any imports or exports, it is not a module, so the Person class becomes global. This behavior makes sense in a browser, but not in a Node.js application. There should be a compiler flag which forbids this behavior and produces a Cannot find name 'Person' error.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 20, 2018

Duplicate of #18232

@mhegazy mhegazy marked this as a duplicate of #18232 Jan 20, 2018
@mhegazy mhegazy added the Duplicate An existing issue was already created label Jan 20, 2018
@shivanshu3
Copy link
Member Author

Thank you very much for finding this issue @mhegazy !

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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