Skip to content

Commit 9fe10a6

Browse files
committed
Merge pull request #6846 from Microsoft/noErrorOnEmptyDtsFile
do not error if typings for external library is empty .d.ts file
1 parent 1754934 commit 9fe10a6

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ namespace ts {
11481148
if (importedFile && resolution.isExternalLibraryImport) {
11491149
// Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files,
11501150
// this check is ok. Otherwise this would be never true for javascript file
1151-
if (!isExternalModule(importedFile)) {
1151+
if (!isExternalModule(importedFile) && importedFile.statements.length) {
11521152
const start = getTokenPosOfNode(file.imports[i], file);
11531153
fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName));
11541154
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/noErrorOnEmptyDts.ts] ////
2+
3+
//// [test.d.ts]
4+
5+
6+
// comment
7+
8+
//// [main.ts]
9+
import "test"
10+
11+
//// [main.js]
12+
"use strict";
13+
require("test");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== c:/node_modules/test.d.ts ===
2+
3+
No type information for this code.
4+
No type information for this code.// comment
5+
No type information for this code.
6+
No type information for this code.=== c:/app/main.ts ===
7+
import "test"
8+
No type information for this code.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== c:/node_modules/test.d.ts ===
2+
3+
No type information for this code.
4+
No type information for this code.// comment
5+
No type information for this code.
6+
No type information for this code.=== c:/app/main.ts ===
7+
import "test"
8+
No type information for this code.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @module: commonjs
2+
3+
// @filename: c:/node_modules/test.d.ts
4+
5+
// comment
6+
7+
// @filename: c:/app/main.ts
8+
import "test"

0 commit comments

Comments
 (0)