Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,16 @@ added:
Enable experimental support for the QUIC protocol.

### `--experimental-repl-typescript`

<!--
added: REPLACEME
-->

> Stability: 1.2 - Release candidate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why release candidate

Enable experimental support for TypeScript stripping in the REPL.

### `--experimental-sea-config`

<!-- YAML
Expand Down
1 change: 1 addition & 0 deletions lib/internal/modules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,5 @@ module.exports = {
stripTypeScriptModuleTypes,
stripTypeScriptTypes,
stripTypeScriptTypesForCoverage,
processTypeScriptCode,
};
19 changes: 17 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ const {
const acornWalk = require('internal/deps/acorn/acorn-walk/dist/walk');
const {
decorateErrorStack,
emitExperimentalWarning,
isError,
deprecate,
SideEffectFreeRegExpPrototypeSymbolReplace,
SideEffectFreeRegExpPrototypeSymbolSplit,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
const { processTypeScriptCode } = require('internal/modules/typescript');
const vm = require('vm');

const { runInThisContext, runInContext } = vm.Script.prototype;
Expand Down Expand Up @@ -141,6 +143,10 @@ const {
const experimentalREPLAwait = getOptionValue(
'--experimental-repl-await',
);
const experimentalREPLTypeScript = getOptionValue(
'--experimental-repl-typescript',
);

const pendingDeprecation = getOptionValue('--pending-deprecation');
const {
REPL_MODE_SLOPPY,
Expand Down Expand Up @@ -241,6 +247,11 @@ function removeProcessNewListener() {

fixReplRequire(module);

const tsOptions = { __proto__: null, mode: 'transform' };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform? We have removed this mode, I don't see that we would want to offer different TS support in REPL than in normal execution?

@marco-ippolito marco-ippolito Jun 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should not transform at all

if (experimentalREPLTypeScript) {
emitExperimentalWarning('TypeScript support in the REPL');
}

// This is the default "writer" value, if none is passed in the REPL options,
// and it can be overridden by custom print functions, such as `probe` or
// `eyes.js`.
Expand Down Expand Up @@ -499,7 +510,9 @@ class REPLServer extends Interface {
const fallbackCode = SideEffectFreeRegExpPrototypeSymbolReplace(/\bawait\b/g, code, '');
try {
makeContextifyScript(
fallbackCode, // code
experimentalREPLTypeScript ?
processTypeScriptCode(fallbackCode, tsOptions) :
fallbackCode, // code
file, // filename,
0, // lineOffset
0, // columnOffset,
Expand Down Expand Up @@ -537,7 +550,9 @@ class REPLServer extends Interface {
code = `'use strict'; void 0;\n${code}`;
}
script = makeContextifyScript(
code, // code
experimentalREPLTypeScript ?
processTypeScriptCode(code, tsOptions) :
code, // code
file, // filename,
0, // lineOffset
0, // columnOffset,
Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
&EnvironmentOptions::experimental_repl_await,
kAllowedInEnvvar,
true);
AddOption("--experimental-repl-typescript",
"experimental TypeScript support in REPL",
&EnvironmentOptions::experimental_repl_typescript,
kAllowedInEnvvar);
AddOption("--experimental-vm-modules",
"experimental ES Module support in vm module",
&EnvironmentOptions::experimental_vm_modules,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class EnvironmentOptions : public Options {
bool allow_ffi = false;
bool allow_worker_threads = false;
bool experimental_repl_await = true;
bool experimental_repl_typescript = false;
bool experimental_vm_modules = EXPERIMENTALS_DEFAULT_VALUE;
bool async_context_frame = true;
bool expose_internals = false;
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-repl-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Flags: --experimental-repl-typescript
'use strict';
require('../common');
const assert = require('assert');

const { startNewREPLServer } = require('../common/repl');

const { input, output } = startNewREPLServer({ terminal: false, prompt: '> ' });

input.emit('data', 'let x: number = 3\n');
assert.match(output.accumulator, /undefined\n> /);

Check failure on line 11 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / x86_64-darwin: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /undefined\n> /. Input: '> Uncaught Error [ERR_NO_TYPESCRIPT]: Node.js is not compiled with TypeScript support\n' + ' at assertTypeScript (node:internal/util:247:11)\n' + ' at node:internal/modules/typescript:35:3 {\n' + " code: 'ERR_NO_TYPESCRIPT'\n" + '}\n' + '> ' at Object.<anonymous> (/Users/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:11:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: '> Uncaught Error [ERR_NO_TYPESCRIPT]: Node.js is not compiled with TypeScript support\n' + ' at assertTypeScript (node:internal/util:247:11)\n' + ' at node:internal/modules/typescript:35:3 {\n' + " code: 'ERR_NO_TYPESCRIPT'\n" + '}\n' + '> ', expected: /undefined\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /Users/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 11 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-darwin: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /undefined\n> /. Input: '> Uncaught Error [ERR_NO_TYPESCRIPT]: Node.js is not compiled with TypeScript support\n' + ' at assertTypeScript (node:internal/util:247:11)\n' + ' at node:internal/modules/typescript:35:3 {\n' + " code: 'ERR_NO_TYPESCRIPT'\n" + '}\n' + '> ' at Object.<anonymous> (/Users/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:11:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: '> Uncaught Error [ERR_NO_TYPESCRIPT]: Node.js is not compiled with TypeScript support\n' + ' at assertTypeScript (node:internal/util:247:11)\n' + ' at node:internal/modules/typescript:35:3 {\n' + " code: 'ERR_NO_TYPESCRIPT'\n" + '}\n' + '> ', expected: /undefined\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /Users/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js
output.accumulator = '';

input.emit('data', 'x\n');
assert.match(output.accumulator, /3\n> /);

// Transform TypeScript to JavaScript and evaluate it
input.emit('data', 'enum Color { Red, Green, Blue }\n');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for:
const foo = () => 'hello world'; foo<Object>();
If should return false. This basically makes sure valid js is evaluated before ts

assert.match(output.accumulator, /undefined\n> /);
output.accumulator = '';

input.emit('data', 'Color.Reed\n');
assert.match(output.accumulator, /0\n> /);

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/node/node/node/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/node/node/node/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /Users/runner/work/node/node/node/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / x86_64-linux: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-3.6.2

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared boringssl-0.20260526.0

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-1.1.1w

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-3.5.6

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-3.0.20

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js

Check failure on line 23 in test/parallel/test-repl-typescript.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-4.0.0

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /0\n> /. Input: 'undefined\n> ' at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js:23:8) at Module._compile (node:internal/modules/cjs/loader:1947:14) at Object..js (node:internal/modules/cjs/loader:2087:10) at Module.load (node:internal/modules/cjs/loader:1669:32) at Module._load (node:internal/modules/cjs/loader:1450:12) at wrapModuleLoad (node:internal/modules/cjs/loader:260:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'undefined\n> ', expected: /0\n> /, operator: 'match', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node --experimental-repl-typescript /home/runner/work/_temp/node-v27.0.0-nightly2026-06-23fc5febe877-slim/test/parallel/test-repl-typescript.js
Loading