Search code examples
typescriptimportmoduleread-eval-print-loopts-node

Is it possible to import a Typescript into a running instance of ts-node REPL?


I would like to test some Typescript code I've code written.

So far, the best way I know to do this is to run ts-node my-file-name.ts.

However I would like to make this more interactive, similar to how Python REPL allows you to import modules and then call then functions from the REPL however you'd like.

For example, a session might look like

$ ts-node
> import my-file-name.ts
> myFunctionFromMyFile("specialParam")
> "you just called a function from my-file-name.ts with param specialParam"

Is this possible with ts-node?


Solution

  • One way I've found to do this is as follows:

    $ ts-node
    > import * as abc from './my-file'
    > abc.myFunction()
    > "works!"