0

I have one main.ts script that I want to use as an entrypoint for my source code. This main.ts script require multiple others typescript files and export then right away :

export const Alpha = require('./Alpha.ts')
export const Beta = require('./Beta.ts')

I then used the typescript compiler to export the .d.ts declaration file of my source code. Now I have a main.d.ts file and two sub-scripts (Alpha.d.ts and Beta.d.ts).

If I create a single .js script and import my main.d.ts entrypoint. I see my two other scripts correctly. But my autocompletion can't follow what is inside the alpha and beta declaration files. I need to import them one by one to get what exported variables and function they have.

How can I access what is inside them by just importing my entrypoint ? I need to expose my source code declaration files without downloading the entire typescript source code.

Thank you for your help.

1
  • It's never valid to import from a path with a .TS extension. Remove the extension or replace it with .JS. const..require won't validate that but it's incorrect Commented Oct 3, 2020 at 1:50

1 Answer 1

1

I think it's:

export * as Alpha from "./Aplha.ts";
export * as Beta from "./Beta.ts"

Look at: https://www.typescriptlang.org/docs/handbook/modules.html#re-exports

You mixed CommonJS / Node.js modules with TypeScript (ES6)

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

1 Comment

This is precisely the wrong way to mix CommonJS and ES6 modules. Is alpha or beta are callable or constructible, that is if they are functions or classes, this code is flat-out broken

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.