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

Duplicate declarations are generated #115

Open
slavafomin opened this issue Jul 27, 2018 · 3 comments
Open

Duplicate declarations are generated #115

slavafomin opened this issue Jul 27, 2018 · 3 comments

Comments

@slavafomin
Copy link

slavafomin commented Jul 27, 2018

Hello!

Thank you for this promising tool!

However, I've tried to use it in order to create a single bundle for my library's type definitions, but I'm getting a single .d.ts file, where definition for the same class is repeated 12 times.

Also, there are multiple modules like this: declare module "src/foo/bar". Is there a way to merge all modules into a single one and avoid duplication? Could you elaborate on what could cause the duplication in the first place?

Thanks!

@Stradivario
Copy link

Stradivario commented Sep 28, 2018

@slavafomin Since i don't see activity and i am just passing by you can check this implementation for this feature https://github.com/rxdi/dts-merge

npm i -g @rxdi/dts-merge
rxdi-merge --name @yournamespace --project . --out dist/index.d.ts

@slavafomin
Copy link
Author

@Stradivario I'm not able to try this out, but thanks nevertheless. This should be used on source files, right?

@Stradivario
Copy link

Stradivario commented Sep 29, 2018

EDIT: As far as i can see now it is using generated .map files :( and i think what you need to do is imposible since you can have same imports from files and if you merge them you cannot understand what is duplicated and what is not.This method by decalaring it module by module gives you freedom to export everything and declare single typo inside tsconfig.json.

// @slavafomin No it is not used on source files it can create source files also but that's another case :).

Example will be the follow:

You have these files index.ts and test2.ts

import { TestClass2 } from './test2';

export const test = 'proba';

export class Test {
    execute1(proba: string) {
        return new TestClass2();
    }
}

export class Test2 {
    execute1(proba: string) {}
}

export class Test3 {
    execute1(proba: string) {}
}

test2.ts

export class TestClass2 {
    execute3(proba: string) {}
}

When you execute

rxdi-merge --name @test --project . --out dist/index.d.ts

You will get the following output from these generated files

declare module '@test/test2' {
	export class TestClass2 {
	    execute3(proba: string): void;
	}

}
declare module '@test' {
	import { TestClass2 } from '@test/test2';
	export const test = "proba";
	export class Test {
	    execute1(proba: string): TestClass2;
	}
	export class Test2 {
	    execute1(proba: string): void;
	}
	export class Test3 {
	    execute1(proba: string): void;
	}

}

P.S. You can check also this example decentralized ;)
https://cloudflare-ipfs.com/ipfs/Qmd4tCCcVpQQftMMU1fxQXPJeR3xwyE9qNzrLXp2xbSrYR

Typings: https://cloudflare-ipfs.com/ipfs/QmVJwuFteVjYwuEQtK95bptVsst9m2WcynSmeXMMXewQrZ

Minified module: https://cloudflare-ipfs.com/ipfs/QmWNVV6G5fAgZRJsk5U9x3A3DKLrn592GByXd5pyXyzuP6

If you want to install it and test it you can try:

npm i @rxdi/core -g
rxdi i Qmd4tCCcVpQQftMMU1fxQXPJeR3xwyE9qNzrLXp2xbSrYR

Usage

import { Test1, Test2, Test3, TestClass2 } from '@test';

P.S2 I just check and i am using the same source like in this repository with little modifications

Regards,
Kristiyan Tachev

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

2 participants