DEV Community

Discussion on: Migrate to Typescript on Node.js

Collapse
 
karataev profile image
Eugene Karataev

Thanks for the great article!

Typescript adopts the es6 import and export syntax, this means you need to change the existing commonjs const a = require('b') and module.exports = c to import a from 'b' and exports default c

I have a relatively big Node project written in JS which I want to convert to TS. Is it necessary to replace all require with import? Is it possible to don't touch require and just add some config property in tsconfig.json or something?

Collapse
 
natelindev profile image
Nathaniel

You can find and replace your const module = require("module") with import module = require("module"), which also works with typescript.
Also there is a vs-code plugin to help you:
marketplace.visualstudio.com/items...

Collapse
 
karataev profile image
Eugene Karataev

Thanks!