1

I am running a react application. The code below does not work because of the following error message:

import = is not supported by @babel/plugin-transform-typescript Please consider using import <moduleName> from '<moduleName>'; alongside Typescript's --allowSyntheticDefaultImports option.

apiTypes.d.ts

declare module ModuleA {
    declare module ModuleB {
        export interface ModuleABInterface {
        }
    }
}

token.ts

import ModuleABInterface = ModuleA.ModuleB.ModuleABInterface
let test: ModuleABInterface

What would be the correct solution to import from nested modules?

4
  • Simplest solution: don't use nested modules? Commented Apr 19, 2021 at 14:22
  • So it is not possible to nest modules? Your answer is not helpful at all.. Commented Apr 19, 2021 at 14:58
  • Btw it looks like you just want a type alias, not an import. Use type ModuleABInterface = ModuleA.ModuleB.ModuleABInterface; let test: ModuleABInterface for that. Commented Apr 19, 2021 at 16:00
  • You can use it, it’s just babel cannot parse it. Problem is in your build tool, not source code. Use the official typescript compiler would solve the problem. Commented Apr 19, 2021 at 16:05

1 Answer 1

3

It's impossible to nest ES6 modules. TypeScript namespaces (that were originally called "modules") can be nested, but should be avoided. And yes, it's impossible to import from them - you can only import the namespace object itself, using normal ES6 import declarations (not the deprecated import = syntax), then access their properties.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.