Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/checker/checker.go
Comment thread
Andarist marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -5161,8 +5161,13 @@ func (c *Checker) checkImportDeclaration(node *ast.Node) {
!hasTypeJsonImportAttribute(node) {
c.error(moduleSpecifier, diagnostics.Importing_a_JSON_file_into_an_ECMAScript_module_requires_a_type_Colon_json_import_attribute_when_module_is_set_to_0, c.moduleKind.String())
}
} else if c.compilerOptions.NoUncheckedSideEffectImports.IsTrue() && importClause == nil {
c.resolveExternalModuleName(node, moduleSpecifier, false)
} else if c.compilerOptions.NoUncheckedSideEffectImports.IsTrueOrUnknown() && importClause == nil {
ignoreErrors := c.compilerOptions.NoCheck.IsTrue()
var errorMessage *diagnostics.Message
if !ignoreErrors {
errorMessage = diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0
}
c.resolveExternalModuleNameWorker(node, moduleSpecifier, errorMessage, ignoreErrors, false /*isForAugmentation*/)
}
}
c.checkImportAttributes(node)
Expand Down
2 changes: 1 addition & 1 deletion internal/tsoptions/declscompiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ var optionsForCompiler = []*CommandLineOption{
AffectsBuildInfo: true,
Category: diagnostics.Modules,
Description: diagnostics.Check_side_effect_imports,
DefaultValueDescription: false,
DefaultValueDescription: true,
Comment thread
jakebailey marked this conversation as resolved.
},

// Source Maps
Expand Down
8 changes: 8 additions & 0 deletions testdata/baselines/reference/compiler/importUrl.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/src/index.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'https://deno.land/std@0.208.0/path/mod.ts'.


==== /src/index.ts (1 errors) ====
import "https://deno.land/std@0.208.0/path/mod.ts"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'https://deno.land/std@0.208.0/path/mod.ts'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/src/index.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'https://deno.land/std@0.208.0/path/mod.ts'.


==== /node_modules/foo/package.json (0 errors) ====
{ "name": "foo", "version": "1.0.0" }

==== /node_modules/foo/index.d.ts (0 errors) ====
export declare function useFoo(): string;

==== /src/index.ts (1 errors) ====
import "https://deno.land/std@0.208.0/path/mod.ts"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'https://deno.land/std@0.208.0/path/mod.ts'.


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
es6ImportWithoutFromClause_1.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClause_0'.


==== es6ImportWithoutFromClause_0.ts (0 errors) ====
export var a = 10;

==== es6ImportWithoutFromClause_1.ts (1 errors) ====
import "es6ImportWithoutFromClause_0";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClause_0'.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseInEs5_0'.


==== es6ImportWithoutFromClauseInEs5_0.ts (0 errors) ====
export var a = 10;

==== es6ImportWithoutFromClauseInEs5_1.ts (1 errors) ====
import "es6ImportWithoutFromClauseInEs5_0";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseInEs5_0'.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
es6ImportWithoutFromClauseNonInstantiatedModule_1.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseNonInstantiatedModule_0'.


==== es6ImportWithoutFromClauseNonInstantiatedModule_0.ts (0 errors) ====
export interface i {
}

==== es6ImportWithoutFromClauseNonInstantiatedModule_1.ts (1 errors) ====
import "es6ImportWithoutFromClauseNonInstantiatedModule_0";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseNonInstantiatedModule_0'.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
client.ts(1,1): error TS1191: An import declaration cannot have modifiers.
client.ts(1,15): error TS2882: Cannot find module or type declarations for side-effect import of 'server'.


==== server.ts (0 errors) ====
export var a = 10;

==== client.ts (1 errors) ====
==== client.ts (2 errors) ====
export import "server";
~~~~~~
!!! error TS1191: An import declaration cannot have modifiers.
!!! error TS1191: An import declaration cannot have modifiers.
~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'server'.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
index.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of './extention'.


==== extension.d.ts (0 errors) ====
declare global {
namespace globalThis {
var test: string;
}
}

export {}

==== index.ts (1 errors) ====
import "./extention";
~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './extention'.

globalThis.tests = "a-b";
console.log(globalThis.test.split("-"));

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
index.tsx(1,8): error TS2882: Cannot find module or type declarations for side-effect import of './jsx'.


==== index.tsx (1 errors) ====
import "./jsx";
~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './jsx'.

var skate: any;
const React = { createElement: skate.h };

class Component {
renderCallback() {
return <div>test</div>;
}
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jsxImportForSideEffectsNonExtantNoError.tsx(4,8): error TS2882: Cannot find module or type declarations for side-effect import of './App.css'.


==== jsxImportForSideEffectsNonExtantNoError.tsx (1 errors) ====
/// <reference path="/.lib/react16.d.ts" />
import * as React from "react";

import "./App.css"; // doesn't actually exist
~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './App.css'.

const tag = <div></div>;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@ let y = x.getA().x;

//// [f.d.ts]
import "array";


//// [DtsFileErrors]


f.d.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'array'.


==== f.d.ts (1 errors) ====
import "array";
~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'array'.

==== array.d.ts (0 errors) ====
declare module "A" {
class A { x: number; }
}

declare module "array" {
import {A} from "A";
global {
interface Array<T> {
getA(): A;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/a.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'foo'.


==== /a.ts (1 errors) ====
import "foo";
~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'foo'.

==== /node_modules/foo/foo.js (0 errors) ====
This file is not read.

==== /node_modules/foo/package.json (0 errors) ====
{ "types": "foo.js" }

Loading