diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 76e81a959790b..50d7f4785be4e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -53178,7 +53178,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const literalType = isLiteralTypeNode(node.parent) || isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent); if (!literalType) { - if (languageVersion < ScriptTarget.ES2020) { + // Don't error on BigInt literals in ambient contexts + if (!(node.flags & NodeFlags.Ambient) && languageVersion < ScriptTarget.ES2020) { if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020)) { return true; } diff --git a/tests/baselines/reference/bigintAmbientMinimal.errors.txt b/tests/baselines/reference/bigintAmbientMinimal.errors.txt new file mode 100644 index 0000000000000..e95b511da01dd --- /dev/null +++ b/tests/baselines/reference/bigintAmbientMinimal.errors.txt @@ -0,0 +1,17 @@ +/main.ts(5,17): error TS2737: BigInt literals are not available when targeting lower than ES2020. + + +==== /ambient.d.ts (0 errors) ==== + declare const fromDts = 789n; + declare namespace Lib { + const value = 999n; + } + +==== /main.ts (1 errors) ==== + // Minimal repro from issue + declare const n = 123n; + + // Non-ambient for comparison + const regular = 456n; + ~~~~ +!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. \ No newline at end of file diff --git a/tests/baselines/reference/bigintAmbientMinimal.js b/tests/baselines/reference/bigintAmbientMinimal.js new file mode 100644 index 0000000000000..d2147fb7d30fb --- /dev/null +++ b/tests/baselines/reference/bigintAmbientMinimal.js @@ -0,0 +1,18 @@ +//// [tests/cases/compiler/bigintAmbientMinimal.ts] //// + +//// [ambient.d.ts] +declare const fromDts = 789n; +declare namespace Lib { + const value = 999n; +} + +//// [main.ts] +// Minimal repro from issue +declare const n = 123n; + +// Non-ambient for comparison +const regular = 456n; + +//// [main.js] +// Non-ambient for comparison +var regular = 456n; diff --git a/tests/baselines/reference/bigintAmbientMinimal.symbols b/tests/baselines/reference/bigintAmbientMinimal.symbols new file mode 100644 index 0000000000000..d438ba1235958 --- /dev/null +++ b/tests/baselines/reference/bigintAmbientMinimal.symbols @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/bigintAmbientMinimal.ts] //// + +=== /ambient.d.ts === +declare const fromDts = 789n; +>fromDts : Symbol(fromDts, Decl(ambient.d.ts, 0, 13)) + +declare namespace Lib { +>Lib : Symbol(Lib, Decl(ambient.d.ts, 0, 29)) + + const value = 999n; +>value : Symbol(value, Decl(ambient.d.ts, 2, 9)) +} + +=== /main.ts === +// Minimal repro from issue +declare const n = 123n; +>n : Symbol(n, Decl(main.ts, 1, 13)) + +// Non-ambient for comparison +const regular = 456n; +>regular : Symbol(regular, Decl(main.ts, 4, 5)) + diff --git a/tests/baselines/reference/bigintAmbientMinimal.types b/tests/baselines/reference/bigintAmbientMinimal.types new file mode 100644 index 0000000000000..086ac1d5676be --- /dev/null +++ b/tests/baselines/reference/bigintAmbientMinimal.types @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/bigintAmbientMinimal.ts] //// + +=== /ambient.d.ts === +declare const fromDts = 789n; +>fromDts : 789n +> : ^^^^ +>789n : 789n +> : ^^^^ + +declare namespace Lib { +>Lib : typeof Lib +> : ^^^^^^^^^^ + + const value = 999n; +>value : 999n +> : ^^^^ +>999n : 999n +> : ^^^^ +} + +=== /main.ts === +// Minimal repro from issue +declare const n = 123n; +>n : 123n +> : ^^^^ +>123n : 123n +> : ^^^^ + +// Non-ambient for comparison +const regular = 456n; +>regular : 456n +> : ^^^^ +>456n : 456n +> : ^^^^ + diff --git a/tests/cases/compiler/bigintAmbientMinimal.ts b/tests/cases/compiler/bigintAmbientMinimal.ts new file mode 100644 index 0000000000000..4bad00279bcfd --- /dev/null +++ b/tests/cases/compiler/bigintAmbientMinimal.ts @@ -0,0 +1,14 @@ +// @target: ES5 + +// @Filename: /ambient.d.ts +declare const fromDts = 789n; +declare namespace Lib { + const value = 999n; +} + +// @Filename: /main.ts +// Minimal repro from issue +declare const n = 123n; + +// Non-ambient for comparison +const regular = 456n; \ No newline at end of file