-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add --importsNotUsedAsValues=preserve-exact
#44137
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
162ad55
Add compiler option
andrewbranch da43639
Require es2015+
andrewbranch a755070
Do not elide any imports or exports in preserve-exact
andrewbranch 8dd2455
Add errors for writing imports/exports that reference elided names
andrewbranch e6df1e5
Improve diagnostics wording
andrewbranch 126069d
Update API baselines
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1364,6 +1364,26 @@ | |
"category": "Error", | ||
"code": 1433 | ||
}, | ||
"'{0}' is a type and must be imported with a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'.": { | ||
"category": "Error", | ||
"code": 1434 | ||
}, | ||
"'{0}' is a type and must be re-exported with a type-only re-export when 'importsNotUsedAsValues' is set to 'preserve-exact'.": { | ||
"category": "Error", | ||
"code": 1435 | ||
}, | ||
"'{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 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 declaration and must be re-exported with a type-only re-export when 'isolatedModules' is enabled.": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of this diagnostic for |
||
"category": "Error", | ||
"code": 1438 | ||
}, | ||
|
||
"The types of '{0}' are incompatible between these types.": { | ||
"category": "Error", | ||
|
@@ -3942,6 +3962,10 @@ | |
"category": "Error", | ||
"code": 5094 | ||
}, | ||
"Option 'importsNotUsedAsValues' may be set to 'preserve-exact' only when 'module' is set to 'es2015' or later.": { | ||
"category": "Error", | ||
"code": 5095 | ||
}, | ||
|
||
"Generates a sourcemap for each corresponding '.d.ts' file.": { | ||
"category": "Message", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/importsNotUsedAsValues_preserve-exact.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
tests/cases/conformance/externalModules/typeOnly/d.ts(1,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. | ||
tests/cases/conformance/externalModules/typeOnly/e.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. | ||
tests/cases/conformance/externalModules/typeOnly/e.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. | ||
|
||
|
||
==== tests/cases/conformance/externalModules/typeOnly/a.ts (0 errors) ==== | ||
export default {}; | ||
export const b = 0; | ||
export const c = 1; | ||
|
||
==== tests/cases/conformance/externalModules/typeOnly/b.ts (0 errors) ==== | ||
import a, { b, c } from "./a"; | ||
|
||
==== tests/cases/conformance/externalModules/typeOnly/c.ts (0 errors) ==== | ||
import * as a from "./a"; | ||
|
||
==== tests/cases/conformance/externalModules/typeOnly/d.ts (1 errors) ==== | ||
export = {}; | ||
~~~~~~~~~~~~ | ||
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. | ||
|
||
==== tests/cases/conformance/externalModules/typeOnly/e.ts (2 errors) ==== | ||
import D = require("./d"); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. | ||
import DD = require("./d"); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. | ||
DD; | ||
|
||
==== tests/cases/conformance/externalModules/typeOnly/f.ts (0 errors) ==== | ||
import type a from "./a"; | ||
import { b, c } from "./a"; | ||
b; | ||
|
43 changes: 43 additions & 0 deletions
43
tests/baselines/reference/importsNotUsedAsValues_preserve-exact.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/importsNotUsedAsValues_preserve-exact.ts] //// | ||
|
||
//// [a.ts] | ||
export default {}; | ||
export const b = 0; | ||
export const c = 1; | ||
|
||
//// [b.ts] | ||
import a, { b, c } from "./a"; | ||
|
||
//// [c.ts] | ||
import * as a from "./a"; | ||
|
||
//// [d.ts] | ||
export = {}; | ||
|
||
//// [e.ts] | ||
import D = require("./d"); | ||
import DD = require("./d"); | ||
DD; | ||
|
||
//// [f.ts] | ||
import type a from "./a"; | ||
import { b, c } from "./a"; | ||
b; | ||
|
||
|
||
//// [a.js] | ||
export default {}; | ||
export var b = 0; | ||
export var c = 1; | ||
//// [b.js] | ||
import a, { b, c } from "./a"; | ||
//// [c.js] | ||
import * as a from "./a"; | ||
//// [d.js] | ||
export {}; | ||
//// [e.js] | ||
DD; | ||
export {}; | ||
//// [f.js] | ||
import { b, c } from "./a"; | ||
b; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The predecessors to these messages try to say
'import type'
and'export type'
instead oftype-only import
andtype-only export
, but these were worded with an eye toward allowing type-only import and export specifiers, as mentioned in the PR description. If we decide not to do that, I would reword these to say'import type'
and'export type'
since there would only be one syntax that can fix the error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the imported thing with this error could technically be an uninstantiated namespace, so “is a type” might be technically incorrect, but I think I prefer calling an uninstantiated namespaces a “type” to calling it an “uninstantiated namespace” in user-facing messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"has no runtime representation"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, more specifically:
"'{0}' is a type or namespace that does not have an associated runtime value. It must be declared as a type-only import when 'importsNotUsedAsValues' is set to 'preserve-exact'."