microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.95k stars 12.47k forks source link

Disallow global namespace pollution: External ambient module declaration should not override other external module typings #5808

Closed falsandtru closed 8 years ago

falsandtru commented 8 years ago

Ambient module declaration scope should be only own module(node package).

// node_modules/foo/types.d.ts
declare module 'foo' {
  export var fizz;
}
declare module 'bar' {
  export var fizz;
}

// node_modules/foo/index.d.ts
import './types.d';
export * from 'foo'; // should need re-exporting of ambient module for exporting as an external module.
                     // or should export only module named by own module(node package) name, but it is weak to typo.

// node_modules/bar/index.d.ts
export var bazz;

// index.ts
import {fizz} from 'foo';
import {bazz} from 'bar'; // should not be type error, this is incorrect error.

bar self hosted typings overridden by ambient module declarations in foo. This is global namespace pollution. Global namespace management should be systematic.

mhegazy commented 8 years ago

While i do agree that global namespace pollution is bad, it does exist and ppl build large scale applications and libraries on top of that. i think there is enough user feedback to allow/regulate more of this side effects rather than to limit it. see https://github.com/Microsoft/TypeScript/issues/5269 and https://github.com/Microsoft/TypeScript/issues/5867 to name a few..

falsandtru commented 8 years ago

All right, thanks.