-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ambient const enum error from use site to import in verbatimModu…
…leSyntax (#86338)
- Loading branch information
1 parent
3568679
commit 3404817
Showing
5 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 |