Allow type and NS references to UMD globals from modules

Fixes #10638
This commit is contained in:
Ryan Cavanaugh 2016-09-14 15:52:54 -07:00
parent 4ce2280559
commit d37391fcfc
4 changed files with 47 additions and 8 deletions

View file

@ -909,8 +909,8 @@ namespace ts {
}
}
// If we're in an external module, we can't reference symbols created from UMD export declarations
if (result && isInExternalModule) {
// If we're in an external module, we can't reference value symbols created from UMD export declarations
if (result && isInExternalModule && (meaning & SymbolFlags.Value) === SymbolFlags.Value) {
const decls = result.declarations;
if (decls && decls.length === 1 && decls[0].kind === SyntaxKind.NamespaceExportDeclaration) {
error(errorLocation, Diagnostics.Identifier_0_must_be_imported_from_a_module, name);

View file

@ -0,0 +1,25 @@
tests/cases/conformance/externalModules/a.ts(7,14): error TS2686: Identifier 'Foo' must be imported from a module
==== tests/cases/conformance/externalModules/a.ts (1 errors) ====
/// <reference path="foo.d.ts" />
import * as ff from './foo';
let y: Foo; // OK in type position
y.foo();
let z: Foo.SubThing; // OK in ns position
let x: any = Foo; // Not OK in value position
~~~
!!! error TS2686: Identifier 'Foo' must be imported from a module
==== tests/cases/conformance/externalModules/foo.d.ts (0 errors) ====
declare class Thing {
foo(): number;
}
declare namespace Thing {
interface SubThing { }
}
export = Thing;
export as namespace Foo;

View file

@ -5,17 +5,25 @@
declare class Thing {
foo(): number;
}
declare namespace Thing {
interface SubThing { }
}
export = Thing;
export as namespace Foo;
//// [a.ts]
/// <reference path="foo.d.ts" />
let y: Foo;
y.foo();
import * as ff from './foo';
let y: Foo; // OK in type position
y.foo();
let z: Foo.SubThing; // OK in ns position
let x: any = Foo; // Not OK in value position
//// [a.js]
/// <reference path="foo.d.ts" />
var y;
"use strict";
var y; // OK in type position
y.foo();
var z; // OK in ns position
var x = Foo; // Not OK in value position

View file

@ -5,11 +5,17 @@
declare class Thing {
foo(): number;
}
declare namespace Thing {
interface SubThing { }
}
export = Thing;
export as namespace Foo;
// @filename: a.ts
/// <reference path="foo.d.ts" />
let y: Foo;
y.foo();
import * as ff from './foo';
let y: Foo; // OK in type position
y.foo();
let z: Foo.SubThing; // OK in ns position
let x: any = Foo; // Not OK in value position