TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published


Turn your tests into types

Transform JavaScript files to TypeScript by collecting V8 runtime type information during test runs.


# Using Yarn:
yarn add @esmbly/transformer-v8

# Or, using NPM:
npm install @esmbly/transformer-v8 --save

Getting Started

Check out Using the V8 transformer for a step-by-step guide on how to get started with @esmbly/transformer-v8 and the command-line interface.


The @esmbly/transformer-v8 transforms JavaScript files to TypeScript based on type information collected from V8. In order to use it, make sure you have @esmbly/cli installed. Under the hood, @esmbly/transformer-v8 uses the experimental Inspector API and the V8 inspector protocol which requires you to have at least Node.js version 10 installed.

In order to collect a V8 type profile about a JavaScript program - the program needs to be executed. When the program is executed, type information can be collected from V8 via the V8 inspector protocol. If a program is covered by a test suite, the test suite can be executed in order to run the program and retrieve a type profile from V8.

The following Esmbly configuration will run jest in order to extract a type profile, and then transform all JavaScript files located in the src directory to TypeScript. Files are outputted to the dist directory.

// esmbly.config.js

const V8 = require('@esmbly/transformer-v8');

module.exports = {
  input: ['./src/**/*.js'],
  transformers: [
      testCommand: `jest`,
  output: [
      format: '.ts',
      outDir: 'dist',
      rootDir: 'src'


The createTransformer() method accepts an optional configuration object (see the V8TransformerOptions interface). The following options are possible.

Option Description Type Default
testCommand The test command to run in order to extract a type profile, e.g. jest --runInBand string
debug Debug whats being printed to stdout/stderr during the test run. boolean false
customRules (optional) An object containing any custom rules which should be applied (existing rules can be overridden). Check out the custom-rule example for further details. CustomRules

Supported test runners

The long term goal is to support any test runner, including simply running node to invoke a program that executes the specified input files. Currently, the following test runners are supported:

  • jest
  • jasmine
  • tape


The type information that can be retrieved from V8 is somewhat experimental. All primitive types are supported, as well as custom classes. However, V8 does provide any detailed information about arrays or objects literals which will be interpreted as any[] and Object.


Further reading


All types of contributions are very much welcome. Check out our Contributing Guide for instructions on how to get started.

Package Sidebar


npm i @esmbly/transformer-v8

Weekly Downloads






Unpacked Size

174 kB

Total Files


Last publish


  • ollelauribostrom