How to do re-export with overrides?
Asked Answered
T

4

19
export * form 'some-library'
export * from './myOverrides'
// error: [ts] Module 'some-module' has already
// exported a member named 'someFunc'.
// Consider explicitly re-exporting to resolve the ambiguity.

import * as SomeLib from 'some-library'
import * as MyOverrides from './myOverrides'

export { ...SomeLib, ...MyOverrides } // syntax error

const Overridden = { ...someLib, ...MyOverrides } // works
export { ...Overridden } // syntax error

I would like to avoid picking out all named exports just to re-export them;

import { a, b, c, d, e, ..... } from 'some-library'
export { a, b, c, d, e, .... }
export * from './myOverrides'
Tempered answered 22/12, 2016 at 23:24 Comment(4)
As far as I can tell, there's no clean way to do this, and no proposals for any way to do this in the future. (It does seem useful though!)Seiler
Hi @Seiler !, see the answer below. I dig up some issues and found it. :)Tempered
Hey @unional! :) Yes, it's good that solutions works for what you need! However, you still have to pick out your overrides individually. I couldn't find a way to do it where you could get the overrides to be exported without ever specifically naming them.Seiler
Yes indeed. But at least I can do that only for the overrides, not the original library. So it should be only a few (finger crossed). :)Tempered
T
29

From Guy Sensei:

https://github.com/systemjs/systemjs/issues/1031#issuecomment-171262430

I need to:

import { theFunction } from './myOverrides'

export * from 'some-library'
export { theFunction }

This works because local exports take priority.

Tempered answered 22/12, 2016 at 23:39 Comment(0)
T
10

I found this to work quite nicely:

import * as packageA from "packageA";
import * as packageB from "packageB";

export default { ...packageA, ...packageB };
Trice answered 12/6, 2021 at 8:8 Comment(1)
This won't work if those packages contain interfaces.Pantagruel
R
1

If you want to export the whole module:

export * as MyOverrides from './myOverrides'

and then you can use it in another file as:

import { MyOverrides } from './some-path'

MyOverrides.someFunc
Rattletrap answered 20/6, 2023 at 20:32 Comment(0)
L
0

Let's say there's 2 modules that you're trying to export everything from. We'll call them apples and oranges.

export * from 'apples'
export * from 'oranges'

But now you're getting the following error.

Module 'oranges' has already exported a member named 'Fruit'. Consider explicitly re-exporting to resolve the ambiguity.ts(2308)

The solution is to simply "re-export to resolve the ambiguity", like below.

export * from 'apples'
export * from 'oranges'
export { Fruit } from 'oranges'

Of course, if I wanted Fruit to come from the apples module then you would write the following.

export * from 'apples'
export * from 'oranges'
export { Fruit } from 'apples'

This has the advantage of simply exporting everything from multiple modules while still being able to resolve ambiguous exports.

Lignify answered 21/6, 2024 at 12:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.