Home  Typescript   How can we ...

how can we use import syntax of commonjs as well as ES6 modules in ts file

You can use both require (CommonJS syntax) and import (ES6 syntax) in TypeScript files, depending on your project configuration and preferences.

Using require (CommonJS)

const http = require('http');

Using import (ES6)

import http from 'http';

Mixing require and import

import http from 'http';
const fs = require('fs');

Module Resolution Strategy

Best Practices

Published on: Jun 26, 2024, 12:59 AM  
 

Comments

Add your comment