Typescript: How to export a variable

There are two different types of export, named and default.

You can have multiple named exports per module but only one default export.

For a named export you can try something like:

// ./file1.ts
const arr = [1,2,3];
export { arr };

Then to import you could use the original statement:

// ./file2
import { arr } from "./file1";
console.log(arr.length);

This will get around the need for arr.arr you mentioned.

How do pirates know that they are pirates? They think, therefore they ARR!!


If you do:

var arr = [1,2,3];
export default arr;

...

import arr from './file1';

Then it should work