Skip to content

importsNotUsedAsValue affects semantic diagnostics #36001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ namespace ts {
error: importsNotUsedAsValues.Error
}),
affectsEmit: true,
affectsSemanticDiagnostics: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types
},
Expand Down
39 changes: 39 additions & 0 deletions src/testRunner/unittests/tscWatch/programUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,45 @@ foo().hello`
]
});

verifyTscWatch({
scenario,
subScenario: "updates errors and emit when importsNotUsedAsValues changes",
commandLineArgs: ["-w"],
sys: () => {
const aFile: File = {
path: `${projectRoot}/a.ts`,
content: `export class C {}`
};
const bFile: File = {
path: `${projectRoot}/b.ts`,
content: `import {C} from './a';
export function f(p: C) { return p; }`
};
const config: File = {
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({ compilerOptions: {} })
};
return createWatchedSystem([aFile, bFile, config, libFile], { currentDirectory: projectRoot });
},
changes: [
sys => {
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "remove" } }));
sys.runQueuedTimeoutCallbacks();
return 'Set to "remove"';
},
sys => {
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "error" } }));
sys.runQueuedTimeoutCallbacks();
return 'Set to "error"';
},
sys => {
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "preserve" } }));
sys.runQueuedTimeoutCallbacks();
return 'Set to "preserve"';
},
]
});

verifyTscWatch({
scenario,
subScenario: "updates errors when ambient modules of program changes",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/a/lib/tsc.js -w
//// [/user/username/projects/myproject/a.ts]
export class C {}

//// [/user/username/projects/myproject/b.ts]
import {C} from './a';
export function f(p: C) { return p; }

//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{}}

//// [/a/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }

//// [/user/username/projects/myproject/a.js]
"use strict";
exports.__esModule = true;
var C = /** @class */ (function () {
function C() {
}
return C;
}());
exports.C = C;


//// [/user/username/projects/myproject/b.js]
"use strict";
exports.__esModule = true;
function f(p) { return p; }
exports.f = f;



Output::
>> Screen clear
12:00:23 AM - Starting compilation in watch mode...



12:00:28 AM - Found 0 errors. Watching for file changes.


Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}

FsWatches::

FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}

exitCode:: ExitStatus.undefined

Change:: Set to "remove"

//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"remove"}}

//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js] file written with same contents

Output::
>> Screen clear
12:00:32 AM - File change detected. Starting incremental compilation...



12:00:39 AM - Found 0 errors. Watching for file changes.


Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":0,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}

FsWatches::

FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}

exitCode:: ExitStatus.undefined

Change:: Set to "error"

//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"error"}}

//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js]
"use strict";
exports.__esModule = true;
require("./a");
function f(p) { return p; }
exports.f = f;



Output::
>> Screen clear
12:00:43 AM - File change detected. Starting incremental compilation...


b.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.


12:00:50 AM - Found 1 error. Watching for file changes.


Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":2,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}

FsWatches::

FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}

exitCode:: ExitStatus.undefined

Change:: Set to "preserve"

//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"preserve"}}

//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js] file written with same contents

Output::
>> Screen clear
12:00:54 AM - File change detected. Starting incremental compilation...



12:01:01 AM - Found 0 errors. Watching for file changes.


Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":1,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}

FsWatches::

FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}

exitCode:: ExitStatus.undefined