Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reexporting module as named export for module library #61

Open
fuzzyfelts opened this issue Jun 15, 2018 · 4 comments
Open

Reexporting module as named export for module library #61

fuzzyfelts opened this issue Jun 15, 2018 · 4 comments

Comments

@fuzzyfelts
Copy link

Hi,

I am trying to use dts-bundle to export a bundle as a module library. I am re-exporting all the exports from another file, and while this works without bundling it doesn't seem to when bundled.

My question is really 2-fold.

  1. Is this a gap/bug in the dts-bundle library?
  2. What should the bundle.d.ts look like?

This is my minimal example. Consider I am trying to publish an 'animals' npm package. It's very simple consisting of the following.

mammals.ts

export class Monkey { }
export class Lion { }
export class Tiger { }

index.ts

import * as mammals from './mammals';
export { mammals }

I want to use it as follows within some other code in another module somewhere

zoo.ts

import { mammals } from 'animals';
new mammals.Lion();

If you create a bundle this using the command

dts-bundle --name bundle --main index.d.ts --outputAsModuleFolder

You get the file

bundle.d.ts

export { mammals };

export class Monkey {
}
export class Lion {
}
export class Tiger {
}

which leads to a typescript error 'Cannot find name mammals'

The initial d.ts files look like this:-

mammals.d.ts

export declare class Monkey {
}
export declare class Lion {
}
export declare class Tiger {
}

index.d.ts

import * as mammals from './mammals';
export { mammals };
@shanehsu
Copy link

shanehsu commented Dec 15, 2018

Similar edge case,

export { value as anotherName } from './some-file'

Will generate

export const value: number

instead of

export const anotherName: number

@im-danwu
Copy link

Hey did you guys find a solution for this?

@shanehsu
Copy link

Better off writing something of our own at this point...

@im-danwu
Copy link

Hahaha yeah this is my first time working with declaration files so I'm surprised there's no automated way of creating these that are... more robust.

@shanehsu I figured out a workaround that's not too bad using namespaces. You would modify the above example as...

mammals.ts

export namespace mammals {
    export class Monkey { }
    export class Lion { }
    export class Tiger { }
}

index.ts

export { mammals } from './mammals';

This actually feels nicer as we don't need to import * as just to export again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants