@@ -168,6 +168,80 @@ declare module "module" {
168168 options ?: RegisterOptions < Data > ,
169169 ) : void ;
170170 function register < Data = any > ( specifier : string | URL , options ?: RegisterOptions < Data > ) : void ;
171+ interface StripTypeScriptTypesOptions {
172+ /**
173+ * Possible values are:
174+ * * `'strip'` Only strip type annotations without performing the transformation of TypeScript features.
175+ * * `'transform'` Strip type annotations and transform TypeScript features to JavaScript.
176+ * @default 'strip'
177+ */
178+ mode ?: "strip" | "transform" | undefined ;
179+ /**
180+ * Only when `mode` is `'transform'`, if `true`, a source map
181+ * will be generated for the transformed code.
182+ * @default false
183+ */
184+ sourceMap ?: boolean | undefined ;
185+ /**
186+ * Specifies the source url used in the source map.
187+ */
188+ sourceUrl ?: string | undefined ;
189+ }
190+ /**
191+ * `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It
192+ * can be used to strip type annotations from TypeScript code before running it
193+ * with `vm.runInContext()` or `vm.compileFunction()`.
194+ * By default, it will throw an error if the code contains TypeScript features
195+ * that require transformation such as `Enums`,
196+ * see [type-stripping](https://nodejs.org/docs/latest-v22.x/api/typescript.md#type-stripping) for more information.
197+ * When mode is `'transform'`, it also transforms TypeScript features to JavaScript,
198+ * see [transform TypeScript features](https://nodejs.org/docs/latest-v22.x/api/typescript.md#typescript-features) for more information.
199+ * When mode is `'strip'`, source maps are not generated, because locations are preserved.
200+ * If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown.
201+ *
202+ * _WARNING_: The output of this function should not be considered stable across Node.js versions,
203+ * due to changes in the TypeScript parser.
204+ *
205+ * ```js
206+ * import { stripTypeScriptTypes } from 'node:module';
207+ * const code = 'const a: number = 1;';
208+ * const strippedCode = stripTypeScriptTypes(code);
209+ * console.log(strippedCode);
210+ * // Prints: const a = 1;
211+ * ```
212+ *
213+ * If `sourceUrl` is provided, it will be used appended as a comment at the end of the output:
214+ *
215+ * ```js
216+ * import { stripTypeScriptTypes } from 'node:module';
217+ * const code = 'const a: number = 1;';
218+ * const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' });
219+ * console.log(strippedCode);
220+ * // Prints: const a = 1\n\n//# sourceURL=source.ts;
221+ * ```
222+ *
223+ * When `mode` is `'transform'`, the code is transformed to JavaScript:
224+ *
225+ * ```js
226+ * import { stripTypeScriptTypes } from 'node:module';
227+ * const code = `
228+ * namespace MathUtil {
229+ * export const add = (a: number, b: number) => a + b;
230+ * }`;
231+ * const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true });
232+ * console.log(strippedCode);
233+ * // Prints:
234+ * // var MathUtil;
235+ * // (function(MathUtil) {
236+ * // MathUtil.add = (a, b)=>a + b;
237+ * // })(MathUtil || (MathUtil = {}));
238+ * // # sourceMappingURL=data:application/json;base64, ...
239+ * ```
240+ * @since v22.13.0
241+ * @param code The code to strip type annotations from.
242+ * @returns The code with type annotations stripped.
243+ */
244+ function stripTypeScriptTypes ( code : string , options ?: StripTypeScriptTypesOptions ) : string ;
171245 /* eslint-enable @definitelytyped/no-unnecessary-generics */
172246 /**
173247 * The `module.syncBuiltinESMExports()` method updates all the live bindings for
0 commit comments