Skip to content

Commit 83eddb5

Browse files
author
Andy Hanson
committed
Produce an error for an augmentation of an untyped module even if moduleNotFoundError is not defined
1 parent 7c5c664 commit 83eddb5

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,9 +1439,8 @@ namespace ts {
14391439
// May be an untyped module. If so, ignore resolutionDiagnostic.
14401440
if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {
14411441
if (isForAugmentation) {
1442-
Debug.assert(!!moduleNotFoundError);
14431442
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1444-
error(errorNode, diag, moduleName, resolvedModule.resolvedFileName);
1443+
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
14451444
}
14461445
else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
14471446
error(errorNode,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/node_modules/augmenter/index.d.ts(3,16): error TS2665: Invalid module name in augmentation. Module 'js' resolves to an untyped module at '/node_modules/js/index.js', which cannot be augmented.
2+
3+
4+
==== /a.ts (0 errors) ====
5+
import { } from "augmenter";
6+
7+
==== /node_modules/augmenter/index.d.ts (1 errors) ====
8+
// This tests that augmenting an untyped module is forbidden even in an ambient context. Contrast with `moduleAugmentationInDependency.ts`.
9+
10+
declare module "js" {
11+
~~~~
12+
!!! error TS2665: Invalid module name in augmentation. Module 'js' resolves to an untyped module at '/node_modules/js/index.js', which cannot be augmented.
13+
export const j: number;
14+
}
15+
export {};
16+
17+
==== /node_modules/js/index.js (0 errors) ====
18+
This file is not processed.
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/untypedModuleImport_withAugmentation2.ts] ////
2+
3+
//// [index.d.ts]
4+
// This tests that augmenting an untyped module is forbidden even in an ambient context. Contrast with `moduleAugmentationInDependency.ts`.
5+
6+
declare module "js" {
7+
export const j: number;
8+
}
9+
export {};
10+
11+
//// [index.js]
12+
This file is not processed.
13+
14+
//// [a.ts]
15+
import { } from "augmenter";
16+
17+
18+
//// [a.js]
19+
"use strict";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @noImplicitReferences: true
2+
// This tests that augmenting an untyped module is forbidden even in an ambient context. Contrast with `moduleAugmentationInDependency.ts`.
3+
4+
// @Filename: /node_modules/augmenter/index.d.ts
5+
declare module "js" {
6+
export const j: number;
7+
}
8+
export {};
9+
10+
// @Filename: /node_modules/js/index.js
11+
This file is not processed.
12+
13+
// @Filename: /a.ts
14+
import { } from "augmenter";

0 commit comments

Comments
 (0)