Skip to content

Commit 98a3fc5

Browse files
Merge pull request #10929 from RyanCavanaugh/fix10638
Allow type and NS references to UMD globals from modules
2 parents 955f2f2 + 9e61168 commit 98a3fc5

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,8 @@ namespace ts {
914914
}
915915
}
916916

917-
// If we're in an external module, we can't reference symbols created from UMD export declarations
918-
if (result && isInExternalModule) {
917+
// If we're in an external module, we can't reference value symbols created from UMD export declarations
918+
if (result && isInExternalModule && (meaning & SymbolFlags.Value) === SymbolFlags.Value) {
919919
const decls = result.declarations;
920920
if (decls && decls.length === 1 && decls[0].kind === SyntaxKind.NamespaceExportDeclaration) {
921921
error(errorLocation, Diagnostics.Identifier_0_must_be_imported_from_a_module, name);
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
tests/cases/conformance/externalModules/a.ts(7,14): error TS2686: Identifier 'Foo' must be imported from a module
2+
3+
4+
==== tests/cases/conformance/externalModules/a.ts (1 errors) ====
5+
/// <reference path="foo.d.ts" />
6+
import * as ff from './foo';
7+
8+
let y: Foo; // OK in type position
9+
y.foo();
10+
let z: Foo.SubThing; // OK in ns position
11+
let x: any = Foo; // Not OK in value position
12+
~~~
13+
!!! error TS2686: Identifier 'Foo' must be imported from a module
14+
15+
==== tests/cases/conformance/externalModules/foo.d.ts (0 errors) ====
16+
17+
declare class Thing {
18+
foo(): number;
19+
}
20+
declare namespace Thing {
21+
interface SubThing { }
22+
}
23+
export = Thing;
24+
export as namespace Foo;
25+

tests/baselines/reference/umd8.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@
55
declare class Thing {
66
foo(): number;
77
}
8+
declare namespace Thing {
9+
interface SubThing { }
10+
}
811
export = Thing;
912
export as namespace Foo;
1013

1114
//// [a.ts]
1215
/// <reference path="foo.d.ts" />
13-
let y: Foo;
14-
y.foo();
16+
import * as ff from './foo';
1517

18+
let y: Foo; // OK in type position
19+
y.foo();
20+
let z: Foo.SubThing; // OK in ns position
21+
let x: any = Foo; // Not OK in value position
1622

1723

1824
//// [a.js]
19-
/// <reference path="foo.d.ts" />
20-
var y;
25+
"use strict";
26+
var y; // OK in type position
2127
y.foo();
28+
var z; // OK in ns position
29+
var x = Foo; // Not OK in value position

tests/cases/conformance/externalModules/umd8.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
declare class Thing {
66
foo(): number;
77
}
8+
declare namespace Thing {
9+
interface SubThing { }
10+
}
811
export = Thing;
912
export as namespace Foo;
1013

1114
// @filename: a.ts
1215
/// <reference path="foo.d.ts" />
13-
let y: Foo;
14-
y.foo();
16+
import * as ff from './foo';
1517

18+
let y: Foo; // OK in type position
19+
y.foo();
20+
let z: Foo.SubThing; // OK in ns position
21+
let x: any = Foo; // Not OK in value position

0 commit comments

Comments
 (0)