0

I'm trying to re-export everything in a namespace from a new module. I've tried the following, which works to a degree:

// index.ts import * as foo from 'foo'; function myFunction() {} // Re-export everything in 'foo' along with myFunction const thing = { ...foo, myFunction, } export = thing; 

This results in a type declaration as follows:

import * as foo from 'foo'; declare function myFunction(); declare const thing: { Foo: typeof foo.Foo; Bar: typeof foo.Bar; myFunction: typeof myFunction; }; export = thing; 

But when I try to consume the types from the generated d.ts file, I get an error:

'Foo' refers to a value, but used as a type 

I suppose this is because Foo and Bar as declared as members of an object. Is there a way to achieve this re-export of existing types in a new module?

2
  • Object spread, namespace imports, and export assignment are all very different. In fact, the error that you encountered is just the tip of the iceberg Commented Jul 11, 2020 at 5:29
  • Yes, I'm sort of learning that the hard way. It may be that the only working solution is just re-exporting each individual member of foo separately, which is what I was hoping to avoid. Commented Jul 13, 2020 at 17:28

1 Answer 1

2

Have you tried this?

export * from 'foo'; export function myFunction() {} 
Sign up to request clarification or add additional context in comments.

1 Comment

This was one of the first ideas tried. Unfortunately, the other module I'm trying to re-export (which is a separate package in fact), uses export = and therefore cannot be re-exported as export *.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.