1

Got a file where an object is exported:

let btypes:{[key:string]:any} = {
"key1":val,
//...
} 
export {btypes}

I also tried export default btypes

When I import it with:

import {btypes} from "../types";

The terminal outputs:

src/tests/parse.test.ts:3:8 - error TS1192: Module '"/abc/types"' has no default export.

Or

src/tests/parse.test.ts:3:9 - error TS2305: Module '"../types"' has no exported member 'btypes'.

Any idea what to look for here?

phentnil
  • 2,195
  • 2
  • 14
  • 22
Minsky
  • 2,277
  • 10
  • 19

2 Answers2

3

Try exporting like this:

export default {btypes};

And import like this:

import * as btypes from '../types';
Mustafa
  • 197
  • 1
  • 7
1

They say: in the playground (and also in the docs):

(...) there is a confusing part of default exports:/ Some exports have documentation that implies you can write an import like this: import req from "request";

However that fails, and then you find a stack overflow which recommends the import as: import * as req from "request";

which is what @Mustafa suggested for default exports.

There is another solution written in the playground. Add this to tsconfig.js:

  1. esModuleInterop:true
  2. allowSyntheticDefaultImports:true

Now import myDefaultExport from './myMod'; should be enough.

Minsky
  • 2,277
  • 10
  • 19