-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Move ambient const enum error from use site to import in verbatimModuleSyntax #59438
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 5 commits into
microsoft:main
from
andrewbranch:bug/verbatimModuleSyntaxAmbientConstEnumImport
Jul 30, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92e7ee9
WIP
andrewbranch ca95e8b
Move ambient const enum error from use site to import in verbatimModu…
andrewbranch ff7457d
Still check accesses when they don’t resolve to an import
andrewbranch 3511b64
Clarify comment and formatting
andrewbranch eff895a
Remove extraneous parens
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
83 changes: 83 additions & 0 deletions
83
...ng-const-enum-from-referenced-project-with-preserveConstEnums-and-verbatimModuleSyntax.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,83 @@ | ||
currentDirectory:: / useCaseSensitiveFileNames: false | ||
Input:: | ||
//// [/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; } | ||
interface ReadonlyArray<T> {} | ||
declare const console: { log(msg: any): void; }; | ||
|
||
//// [/src/no-preserve/index.d.ts] | ||
export declare const enum F { A = 1 } | ||
|
||
//// [/src/no-preserve/index.ts] | ||
export const enum E { A = 1 } | ||
|
||
//// [/src/no-preserve/tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"declaration": true, | ||
"preserveConstEnums": false | ||
} | ||
} | ||
|
||
//// [/src/preserve/index.d.ts] | ||
export declare const enum E { A = 1 } | ||
|
||
//// [/src/preserve/index.ts] | ||
export const enum E { A = 1 } | ||
|
||
//// [/src/preserve/tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"declaration": true, | ||
"preserveConstEnums": true | ||
} | ||
} | ||
|
||
//// [/src/project/index.ts] | ||
import { E } from "../preserve"; | ||
import { F } from "../no-preserve"; | ||
E.A; F.A; | ||
|
||
//// [/src/project/tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"module": "preserve", | ||
"verbatimModuleSyntax": true | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../preserve" | ||
}, | ||
{ | ||
"path": "../no-preserve" | ||
} | ||
] | ||
} | ||
|
||
|
||
|
||
Output:: | ||
/lib/tsc --p src/project --pretty false | ||
src/project/index.ts(2,10): error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
||
|
||
//// [/src/project/index.js] | ||
import { E } from "../preserve"; | ||
import { F } from "../no-preserve"; | ||
E.A; | ||
F.A; | ||
|
||
|
27 changes: 27 additions & 0 deletions
27
tests/baselines/reference/verbatimModuleSyntaxAmbientConstEnum.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,27 @@ | ||
/a.ts(1,10): error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
/a.ts(4,1): error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
/b.ts(1,10): error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
|
||
|
||
==== /node_modules/pkg/index.d.ts (0 errors) ==== | ||
export declare const enum E { A, B, C } | ||
declare global { | ||
const enum F { A, B, C } | ||
} | ||
|
||
==== /a.ts (2 errors) ==== | ||
import { E } from "pkg"; // Error | ||
~ | ||
!!! error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
import type { E as _E } from "pkg"; // Ok | ||
console.log(E.A); // Ok | ||
F.A; // Error | ||
~ | ||
!!! error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
|
||
==== /b.ts (1 errors) ==== | ||
export { E } from "pkg"; // Error | ||
~ | ||
!!! error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled. | ||
export type { E as _E } from "pkg"; // Ok | ||
|
21 changes: 21 additions & 0 deletions
21
tests/cases/conformance/externalModules/verbatimModuleSyntaxAmbientConstEnum.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,21 @@ | ||
// @verbatimModuleSyntax: true | ||
// @target: esnext | ||
// @module: preserve | ||
// @noEmit: true | ||
// @noTypesAndSymbols: true | ||
|
||
// @Filename: /node_modules/pkg/index.d.ts | ||
export declare const enum E { A, B, C } | ||
declare global { | ||
const enum F { A, B, C } | ||
} | ||
|
||
// @Filename: /a.ts | ||
import { E } from "pkg"; // Error | ||
import type { E as _E } from "pkg"; // Ok | ||
console.log(E.A); // Ok | ||
F.A; // Error | ||
|
||
// @Filename: /b.ts | ||
export { E } from "pkg"; // Error | ||
export type { E as _E } from "pkg"; // Ok |
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.