-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Error on export default of type: issue https://github.com/microsoft/TypeScript/issues/55087 #55097
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
andrewbranch
merged 10 commits into
microsoft:main
from
EliLichtblau:eli/no-type-default-exports
Nov 20, 2023
Merged
Error on export default of type: issue https://github.com/microsoft/TypeScript/issues/55087 #55097
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f5a5b0
Change and tests accepted
c5494a1
fix lint
9ee5472
Merge branch 'main' into eli/no-type-default-exports
andrewbranch 75a4c20
Add tests and fix implementation
andrewbranch 981a1fd
Remove unnecessary parts of baseline
andrewbranch 12f9ae6
Fix export assignment emit
andrewbranch 7064af4
Delete old baselines
andrewbranch 7b2dee6
Fix false error on unresolved import
andrewbranch 392167d
Merge branch 'main' into eli/no-type-default-exports
andrewbranch 6f27b59
Update baseline with change from main
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
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
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/exportDeclaration(isolatedmodules=true).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,25 @@ | ||
/b.ts(3,5): error TS1362: 'A' cannot be used as a value because it was exported using 'export type'. | ||
/d.ts(2,10): error TS1291: 'A' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'A' is imported. | ||
|
||
|
||
==== /a.ts (0 errors) ==== | ||
class A {} | ||
export type { A }; | ||
|
||
==== /b.ts (1 errors) ==== | ||
import { A } from './a'; | ||
declare const a: A; | ||
new A(); | ||
~ | ||
!!! error TS1362: 'A' cannot be used as a value because it was exported using 'export type'. | ||
!!! related TS1377 /a.ts:2:15: 'A' was exported here. | ||
|
||
==== /c.ts (0 errors) ==== | ||
import type { A } from './a'; | ||
export = A; | ||
|
||
==== /d.ts (1 errors) ==== | ||
import { A } from './a'; | ||
export = A; | ||
~ | ||
!!! error TS1291: 'A' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'A' is imported. |
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/exportDeclaration(isolatedmodules=true).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,37 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/exportDeclaration.ts] //// | ||
|
||
//// [a.ts] | ||
class A {} | ||
export type { A }; | ||
|
||
//// [b.ts] | ||
import { A } from './a'; | ||
declare const a: A; | ||
new A(); | ||
|
||
//// [c.ts] | ||
import type { A } from './a'; | ||
export = A; | ||
|
||
//// [d.ts] | ||
import { A } from './a'; | ||
export = A; | ||
|
||
//// [a.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var A = /** @class */ (function () { | ||
function A() { | ||
} | ||
return A; | ||
}()); | ||
//// [b.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
new A(); | ||
//// [c.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//// [d.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/exportDeclaration(isolatedmodules=true).symbols
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,34 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/exportDeclaration.ts] //// | ||
|
||
=== /a.ts === | ||
class A {} | ||
>A : Symbol(A, Decl(a.ts, 0, 0)) | ||
|
||
export type { A }; | ||
>A : Symbol(A, Decl(a.ts, 1, 13)) | ||
|
||
=== /b.ts === | ||
import { A } from './a'; | ||
>A : Symbol(A, Decl(b.ts, 0, 8)) | ||
|
||
declare const a: A; | ||
>a : Symbol(a, Decl(b.ts, 1, 13)) | ||
>A : Symbol(A, Decl(b.ts, 0, 8)) | ||
|
||
new A(); | ||
>A : Symbol(A, Decl(b.ts, 0, 8)) | ||
|
||
=== /c.ts === | ||
import type { A } from './a'; | ||
>A : Symbol(A, Decl(c.ts, 0, 13)) | ||
|
||
export = A; | ||
>A : Symbol(A, Decl(c.ts, 0, 13)) | ||
|
||
=== /d.ts === | ||
import { A } from './a'; | ||
>A : Symbol(A, Decl(d.ts, 0, 8)) | ||
|
||
export = A; | ||
>A : Symbol(A, Decl(d.ts, 0, 8)) | ||
|
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/exportDeclaration(isolatedmodules=true).types
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,34 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/exportDeclaration.ts] //// | ||
|
||
=== /a.ts === | ||
class A {} | ||
>A : A | ||
|
||
export type { A }; | ||
>A : A | ||
|
||
=== /b.ts === | ||
import { A } from './a'; | ||
>A : typeof A | ||
|
||
declare const a: A; | ||
>a : A | ||
|
||
new A(); | ||
>new A() : A | ||
>A : typeof A | ||
|
||
=== /c.ts === | ||
import type { A } from './a'; | ||
>A : A | ||
|
||
export = A; | ||
>A : A | ||
|
||
=== /d.ts === | ||
import { A } from './a'; | ||
>A : typeof A | ||
|
||
export = A; | ||
>A : A | ||
|
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
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/isolatedModulesExportDeclarationType.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,36 @@ | ||
/test1.ts(1,10): error TS2865: Import 'T' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
/test2.ts(1,10): error TS2440: Import declaration conflicts with local declaration of 'T'. | ||
/test2.ts(3,16): error TS1292: 'T' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'export type { T as default }'. | ||
/test3.ts(2,16): error TS1292: 'T' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'export type { T as default }'. | ||
|
||
|
||
==== /type.ts (0 errors) ==== | ||
export type T = number; | ||
|
||
==== /test1.ts (1 errors) ==== | ||
import { T } from "./type"; | ||
~ | ||
!!! error TS2865: Import 'T' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
const T = 0; // Error as of #56354 | ||
export default T; // Ok | ||
|
||
==== /test2.ts (2 errors) ==== | ||
import { T } from "./type"; | ||
~ | ||
!!! error TS2440: Import declaration conflicts with local declaration of 'T'. | ||
type T = number; // Merge error | ||
export default T; // Transpiler could assume the alias resolves to a value? | ||
~ | ||
!!! error TS1292: 'T' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'export type { T as default }'. | ||
|
||
==== /test3.ts (1 errors) ==== | ||
import { T } from "./type"; | ||
export default T; // Error | ||
~ | ||
!!! error TS1292: 'T' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'export type { T as default }'. | ||
|
||
==== /test4.ts (0 errors) ==== | ||
// @ts-expect-error | ||
import unresolved from "./doesntexist"; | ||
export default unresolved; | ||
|
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.
Oops!
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.
Yeppp