-
Notifications
You must be signed in to change notification settings - Fork 12.9k
isolatedModules error on global shadowed by imported type #56732
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
67 changes: 67 additions & 0 deletions
67
...dulesShadowGlobalTypeNotValue(isolatedmodules=false,verbatimmodulesyntax=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,67 @@ | ||
bad.ts(1,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,10): error TS1484: 'Date' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,16): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,16): error TS1484: 'Event' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
good.ts(2,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
|
||
|
||
==== ./types.ts (0 errors) ==== | ||
export interface Date { | ||
day: number; | ||
month: number; | ||
year: number; | ||
} | ||
|
||
export namespace Event { | ||
export type T = any; | ||
} | ||
|
||
==== ./node.d.ts (0 errors) ==== | ||
declare module 'node:console' { | ||
global { | ||
interface Console { | ||
Console: console.ConsoleConstructor; | ||
} | ||
namespace console { | ||
interface ConsoleConstructor { | ||
prototype: Console; | ||
new (): Console; | ||
} | ||
} | ||
var console: Console; | ||
} | ||
export = globalThis.console; | ||
} | ||
|
||
==== ./bad.ts (4 errors) ==== | ||
import { Date, Event } from './types'; | ||
~~~~ | ||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
~~~~ | ||
!!! error TS1484: 'Date' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
~~~~~ | ||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
~~~~~ | ||
!!! error TS1484: 'Event' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
|
||
==== ./good.ts (1 errors) ==== | ||
import type { Date, Event } from './types'; | ||
import { Console } from 'node:console'; | ||
~~~~~~~ | ||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
const baz: Console = new Console(); | ||
|
58 changes: 58 additions & 0 deletions
58
...dulesShadowGlobalTypeNotValue(isolatedmodules=true,verbatimmodulesyntax=false).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,58 @@ | ||
bad.ts(1,10): error TS2866: Import 'Date' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
bad.ts(1,16): error TS2866: Import 'Event' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
|
||
|
||
==== ./types.ts (0 errors) ==== | ||
export interface Date { | ||
day: number; | ||
month: number; | ||
year: number; | ||
} | ||
|
||
export namespace Event { | ||
export type T = any; | ||
} | ||
|
||
==== ./node.d.ts (0 errors) ==== | ||
declare module 'node:console' { | ||
global { | ||
interface Console { | ||
Console: console.ConsoleConstructor; | ||
} | ||
namespace console { | ||
interface ConsoleConstructor { | ||
prototype: Console; | ||
new (): Console; | ||
} | ||
} | ||
var console: Console; | ||
} | ||
export = globalThis.console; | ||
} | ||
|
||
==== ./bad.ts (2 errors) ==== | ||
import { Date, Event } from './types'; | ||
~~~~ | ||
!!! error TS2866: Import 'Date' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
~~~~~ | ||
!!! error TS2866: Import 'Event' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
|
||
==== ./good.ts (0 errors) ==== | ||
import type { Date, Event } from './types'; | ||
import { Console } from 'node:console'; | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
const baz: Console = new Console(); | ||
|
73 changes: 73 additions & 0 deletions
73
...odulesShadowGlobalTypeNotValue(isolatedmodules=true,verbatimmodulesyntax=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,73 @@ | ||
bad.ts(1,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,10): error TS1484: 'Date' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,10): error TS2866: Import 'Date' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
bad.ts(1,16): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,16): error TS1484: 'Event' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
bad.ts(1,16): error TS2866: Import 'Event' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
good.ts(2,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
|
||
|
||
==== ./types.ts (0 errors) ==== | ||
export interface Date { | ||
day: number; | ||
month: number; | ||
year: number; | ||
} | ||
|
||
export namespace Event { | ||
export type T = any; | ||
} | ||
|
||
==== ./node.d.ts (0 errors) ==== | ||
declare module 'node:console' { | ||
global { | ||
interface Console { | ||
Console: console.ConsoleConstructor; | ||
} | ||
namespace console { | ||
interface ConsoleConstructor { | ||
prototype: Console; | ||
new (): Console; | ||
} | ||
} | ||
var console: Console; | ||
} | ||
export = globalThis.console; | ||
} | ||
|
||
==== ./bad.ts (6 errors) ==== | ||
import { Date, Event } from './types'; | ||
~~~~ | ||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
~~~~ | ||
!!! error TS1484: 'Date' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
~~~~ | ||
!!! error TS2866: Import 'Date' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
~~~~~ | ||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
~~~~~ | ||
!!! error TS1484: 'Event' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. | ||
~~~~~ | ||
!!! error TS2866: Import 'Event' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled. | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
|
||
==== ./good.ts (1 errors) ==== | ||
import type { Date, Event } from './types'; | ||
import { Console } from 'node:console'; | ||
~~~~~~~ | ||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
const baz: Console = new Console(); | ||
|
54 changes: 54 additions & 0 deletions
54
tests/cases/compiler/isolatedModulesShadowGlobalTypeNotValue.ts
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,54 @@ | ||
// @isolatedModules: false, true | ||
// @verbatimModuleSyntax: false, true | ||
// @noEmit: true | ||
// @noTypesAndSymbols: true | ||
|
||
// @filename: ./types.ts | ||
export interface Date { | ||
day: number; | ||
month: number; | ||
year: number; | ||
} | ||
|
||
export namespace Event { | ||
export type T = any; | ||
} | ||
|
||
// @filename: ./node.d.ts | ||
declare module 'node:console' { | ||
global { | ||
interface Console { | ||
Console: console.ConsoleConstructor; | ||
} | ||
namespace console { | ||
interface ConsoleConstructor { | ||
prototype: Console; | ||
new (): Console; | ||
} | ||
} | ||
var console: Console; | ||
} | ||
export = globalThis.console; | ||
} | ||
|
||
// @filename: ./bad.ts | ||
import { Date, Event } from './types'; | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
|
||
// @filename: ./good.ts | ||
import type { Date, Event } from './types'; | ||
import { Console } from 'node:console'; | ||
function foo(a: Date) { | ||
const b = new Date(a.year, a.month, a.day); | ||
return b.getTime(); | ||
} | ||
function bar() { | ||
return new Event('bar') as Event.T; | ||
} | ||
const baz: Console = new Console(); |
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.
Uh oh!
There was an error while loading. Please reload this page.