Skip to content

Commit bb54a6a

Browse files
sandersnmhegazy
authored andcommitted
Typeof can refer to a class in a previous file with --out (#16269)
* Typeof can refer block-scoped values in prev file `typeof C` can now refer to block-scoped values in a preceding file when used with --out or --outFile. Previously this was not allowed with --out or --outFile since they depend on file order for their emit. * Test `typeof C` reference across files with --out
1 parent 8ace7b8 commit bb54a6a

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ namespace ts {
740740
if (declarationFile !== useFile) {
741741
if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
742742
(!compilerOptions.outFile && !compilerOptions.out) ||
743+
isInTypeQuery(usage) ||
743744
isInAmbientContext(declaration)) {
744745
// nodes are in different files and order cannot be determined
745746
return true;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts] ////
2+
3+
//// [c.ts]
4+
let foo: typeof C;
5+
//// [b.ts]
6+
class C { }
7+
8+
9+
//// [foo.js]
10+
var foo;
11+
var C = (function () {
12+
function C() {
13+
}
14+
return C;
15+
}());
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/c.ts ===
2+
let foo: typeof C;
3+
>foo : Symbol(foo, Decl(c.ts, 0, 3))
4+
>C : Symbol(C, Decl(b.ts, 0, 0))
5+
6+
=== tests/cases/compiler/b.ts ===
7+
class C { }
8+
>C : Symbol(C, Decl(b.ts, 0, 0))
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/c.ts ===
2+
let foo: typeof C;
3+
>foo : typeof C
4+
>C : typeof C
5+
6+
=== tests/cases/compiler/b.ts ===
7+
class C { }
8+
>C : C
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @outFile: foo.js
2+
// @Filename: c.ts
3+
let foo: typeof C;
4+
// @Filename: b.ts
5+
class C { }

0 commit comments

Comments
 (0)