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?
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...
Thanks for the great article!
I have a relatively big Node project written in JS which I want to convert to TS. Is it necessary to replace all
require
withimport
? Is it possible to don't touchrequire
and just add some config property intsconfig.json
or something?You can find and replace your
const module = require("module")
withimport module = require("module")
, which also works with typescript.Also there is a vs-code plugin to help you:
marketplace.visualstudio.com/items...
Thanks!