# VS Code JavaScript IntelliSense and/or TypeScript Support

Out of the box, prescript comes with a type declaration file. This means it will work with VS Code IntelliSense for JavaScript right away, even if you are using just JavaScript.

Screenshot

# Writing tests in TypeScript

If you want to write tests in TypeScript, you can configure prescript to inject ts-node into the Node.js runtime. This will let you write tests in TypeScript.

  1. Install ts-node.

  2. Create prescript.config.js with this contents:

    require('ts-node/register/transpile-only')
    

# Declaring the type of prescript state

The type of state variable, passed to your action functions in action() and defer() APIs defaults to an unknown type.

Screenshot

That means that by default you don’t get autocompletion when writing actions:

Screenshot

To fix this, you can define the type of your prescript state by following these steps:

  1. If you are not using TypeScript, set up a JavaScript project in VS Code by creating a jsconfig.json file at the root of your project.

    {
      "compilerOptions": { "target": "ES6" },
      "include": ["tests"],
      "exclude": ["node_modules", "**/node_modules/*"]
    }
    

    Reload VS Code after creating this file to make sure that VS Code picks up the configuration file.

  2. Create a file state.d.ts which will contain the type definition of your state. It should declare an interface GlobalState in a global namespace Prescript, thus triggering declaration merging. Here’s an example:

    import * as puppeteer from 'puppeteer'
    
    declare global {
      namespace Prescript {
        interface GlobalState {
          browser: puppeteer.Browser
          page: puppeteer.Page
        }
      }
    }
    
    export {}
    

    Anything you add to the GlobalState interface inside Prescript namespace will show up in the type of the state variable.

  3. Now you have IntelliSense for your test state!

Screenshot