How to compile typescript to use CommonJS and import/export?

For example, I have an index.ts file in which a function that returns the sum of two numbers is exported via export. And also the test.js file which imports the function from the already compiled index.js file,how can I make it so that I can import the function through require and also import? Thanks in advance!