Skip to content

Add --preserveValueImports #44619

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve diagnostics wording
  • Loading branch information
andrewbranch committed May 18, 2021
commit e6df1e5e5f4a73fc93000af51e5deb860992dd7f
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38095,7 +38095,7 @@ namespace ts {
if (compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.PreserveExact) {
const message = isType
? Diagnostics._0_is_a_type_and_must_be_imported_with_a_type_only_import_when_importsNotUsedAsValues_is_set_to_preserve_exact
: Diagnostics._0_resolves_to_a_type_only_reference_and_must_be_imported_with_a_type_only_import_when_importsNotUsedAsValues_is_set_to_preserve_exact;
: Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_with_a_type_only_import_when_importsNotUsedAsValues_is_set_to_preserve_exact;
const name = idText(node.kind === SyntaxKind.ImportSpecifier ? node.propertyName || node.name : node.name!);
addTypeOnlyDeclarationRelatedInfo(
error(node, message, name),
Expand All @@ -38119,9 +38119,9 @@ namespace ts {
}
const message =
compilerOptions.isolatedModules && isType ? Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type :
compilerOptions.isolatedModules && !isType ? Diagnostics._0_resolves_to_a_type_only_reference_and_must_be_re_exported_with_a_type_only_re_export_when_isolatedModules_is_enabled :
compilerOptions.isolatedModules && !isType ? Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_re_exported_with_a_type_only_re_export_when_isolatedModules_is_enabled :
isType ? Diagnostics._0_is_a_type_and_must_be_re_exported_with_a_type_only_re_export_when_importsNotUsedAsValues_is_set_to_preserve_exact :
Diagnostics._0_resolves_to_a_type_only_reference_and_must_be_re_exported_with_a_type_only_re_export_when_importsNotUsedAsValues_is_set_to_preserve_exact;
Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_re_exported_with_a_type_only_re_export_when_importsNotUsedAsValues_is_set_to_preserve_exact;
const name = idText(node.propertyName || node.name);
addTypeOnlyDeclarationRelatedInfo(
error(node, message, name),
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1372,15 +1372,15 @@
"category": "Error",
"code": 1435
},
"'{0}' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.": {
"'{0}' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.": {
"category": "Error",
"code": 1436
},
"'{0}' resolves to a type-only reference and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.": {
"'{0}' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.": {
"category": "Error",
"code": 1437
},
"'{0}' resolves to a type-only reference and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.": {
"'{0}' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.": {
"category": "Error",
"code": 1438
},
Expand Down Expand Up @@ -3962,7 +3962,7 @@
"category": "Error",
"code": 5094
},
"Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.": {
"Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.": {
"category": "Error",
"code": 5095
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3296,7 +3296,7 @@ namespace ts {
}

if (options.importsNotUsedAsValues === ImportsNotUsedAsValues.PreserveExact && getEmitModuleKind(options) < ModuleKind.ES2015) {
createOptionValueDiagnostic("importsNotUsedAsValues", Diagnostics.Option_importsNotUsedAsValues_may_only_be_set_to_preserve_exact_when_module_is_set_to_es2015_or_later);
createOptionValueDiagnostic("importsNotUsedAsValues", Diagnostics.Option_importsNotUsedAsValues_may_be_set_to_preserve_exact_only_when_module_is_set_to_es2015_or_later);
}

// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
tests/cases/conformance/externalModules/typeOnly/c.ts(1,8): error TS1434: 'DefaultA' is a type and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/c.ts(2,10): error TS1434: 'A' is a type and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/c.ts(3,8): error TS1436: 'DefaultB' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/c.ts(4,10): error TS1436: 'B' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/c.ts(3,8): error TS1436: 'DefaultB' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/c.ts(4,10): error TS1436: 'B' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/d.ts(1,10): error TS1435: 'A' is a type and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/d.ts(2,10): error TS1437: 'B' resolves to a type-only reference and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/d.ts(2,10): error TS1437: 'B' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/e.ts(1,10): error TS1434: 'AA' is a type and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/e.ts(1,14): error TS1436: 'BB' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/e.ts(1,14): error TS1436: 'BB' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/f.ts(3,10): error TS1435: 'A' is a type and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/f.ts(3,13): error TS1437: 'B' resolves to a type-only reference and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
tests/cases/conformance/externalModules/typeOnly/f.ts(3,13): error TS1437: 'B' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.


==== tests/cases/conformance/externalModules/typeOnly/a.ts (0 errors) ====
Expand All @@ -27,11 +27,11 @@ tests/cases/conformance/externalModules/typeOnly/f.ts(3,13): error TS1437: 'B' r
!!! error TS1434: 'A' is a type and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
import DefaultB from "./b";
~~~~~~~~
!!! error TS1436: 'DefaultB' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! error TS1436: 'DefaultB' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! related TS1377 tests/cases/conformance/externalModules/typeOnly/b.ts:2:18: 'DefaultB' was exported here.
import { B } from "./b";
~
!!! error TS1436: 'B' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! error TS1436: 'B' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! related TS1377 tests/cases/conformance/externalModules/typeOnly/b.ts:2:15: 'B' was exported here.

==== tests/cases/conformance/externalModules/typeOnly/c.fixed.ts (0 errors) ====
Expand All @@ -46,7 +46,7 @@ tests/cases/conformance/externalModules/typeOnly/f.ts(3,13): error TS1437: 'B' r
!!! error TS1435: 'A' is a type and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
export { B as BB } from "./b";
~~~~~~~
!!! error TS1437: 'B' resolves to a type-only reference and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! error TS1437: 'B' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! related TS1377 tests/cases/conformance/externalModules/typeOnly/b.ts:2:15: 'B' was exported here.

==== tests/cases/conformance/externalModules/typeOnly/d.fixed.ts (0 errors) ====
Expand All @@ -58,7 +58,7 @@ tests/cases/conformance/externalModules/typeOnly/f.ts(3,13): error TS1437: 'B' r
~~
!!! error TS1434: 'AA' is a type and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
~~
!!! error TS1436: 'BB' resolves to a type-only reference and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! error TS1436: 'BB' resolves to a type-only declaration and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! related TS1377 tests/cases/conformance/externalModules/typeOnly/b.ts:2:15: 'BB' was exported here.

==== tests/cases/conformance/externalModules/typeOnly/e.fixed.ts (0 errors) ====
Expand All @@ -71,7 +71,7 @@ tests/cases/conformance/externalModules/typeOnly/f.ts(3,13): error TS1437: 'B' r
~
!!! error TS1435: 'A' is a type and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
~~~~~~~
!!! error TS1437: 'B' resolves to a type-only reference and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! error TS1437: 'B' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.
!!! related TS1376 tests/cases/conformance/externalModules/typeOnly/f.ts:2:15: 'B' was imported here.

==== tests/cases/conformance/externalModules/typeOnly/f.fixed.ts (0 errors) ====
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error TS5095: Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.
error TS5095: Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.


!!! error TS5095: Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.
!!! error TS5095: Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.
==== tests/cases/conformance/externalModules/typeOnly/importsNotUsedAsValues_preserve-exact_module.ts (0 errors) ====
export {};

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error TS5095: Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.
error TS5095: Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.


!!! error TS5095: Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.
!!! error TS5095: Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.
==== tests/cases/conformance/externalModules/typeOnly/importsNotUsedAsValues_preserve-exact_module.ts (0 errors) ====
export {};

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error TS5095: Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.
error TS5095: Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.


!!! error TS5095: Option 'importsNotUsedAsValues' may only be set to 'preserve-exact' when 'module' is set to 'es2015' or later.
!!! error TS5095: Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.
==== tests/cases/conformance/externalModules/typeOnly/importsNotUsedAsValues_preserve-exact_module.ts (0 errors) ====
export {};

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/user.ts(2,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
/user.ts(17,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
/user.ts(25,10): error TS1438: 'CC' resolves to a type-only reference and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.
/user.ts(25,10): error TS1438: 'CC' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.


==== /user.ts (3 errors) ====
Expand Down Expand Up @@ -34,7 +34,7 @@
import { C as CC } from "./reExportValueAsTypeOnly";
export { CC };
~~
!!! error TS1438: 'CC' resolves to a type-only reference and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.
!!! error TS1438: 'CC' resolves to a type-only declaration and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.
!!! related TS1377 /reExportValueAsTypeOnly.ts:1:15: 'CC' was exported here.

==== /exportT.ts (0 errors) ====
Expand Down