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

Consider making Type<T> public again #3709

Closed
marklbarlow opened this issue Sep 27, 2022 · 6 comments · Fixed by #3795
Closed

Consider making Type<T> public again #3709

marklbarlow opened this issue Sep 27, 2022 · 6 comments · Fixed by #3795

Comments

@marklbarlow
Copy link

We use ng-mocks to create re-usable mock modules so we don't need to repeat our mocking set-up across apps. This is done using standard Angular CLI library projects and ng-packagr.

Since v14, the following interface is no long public:

export interface Type<T> extends Function {
  new (...args: any[]): T;
}

This means that usage such as the below is no longer possible:

export const FooTestingModule = MockModule(FooComponentsModule);

Compilation now results in the following error:

Exported variable 'FooTestingModule ' has or is using name 'Type' from external module "E:/code/Foo/node_modules/ng-mocks/index" but cannot be named.

Could this interface be made public again or a different approach suggested to satisfy the above requirement?

@satanTime
Copy link
Member

Hi @marklbarlow

Thanks for reporting the issue.
Could you provide a min project which fails with it?

@marklbarlow
Copy link
Author

Hi @satanTime,

I've created an example at https://github.com/marklbarlow/ng-mocks-example

You just need to:
npm install
ng build example

@satanTime
Copy link
Member

Hi @marklbarlow, thank you for the repo.

now I see the problem. Is there a reason why you put mocks in the production build?

Usually, I would expect ng-mocks in tests only.

@marklbarlow
Copy link
Author

Hi @satanTime , we put mocks in a production build as we're creating a set of re-usable mocks that can be used across all our apps. Without this we need to repeat our mocking set up / definitions a dozen times across our various repos...

@satanTime
Copy link
Member

oki-doki. I'll implement a test and return back the exports of required types.

Type<T> was hidden to avoid imports from ng-mocks, because it exists in @angular/core and basically should be imported from there.

I'll try to add jsdoc to let users know about the right import, if it's possible.

satanTime added a commit to satanTime/ng-mocks that referenced this issue Oct 9, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Oct 9, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Oct 9, 2022
satanTime added a commit that referenced this issue Oct 9, 2022
fix(core): exporting internal types #3709
@satanTime
Copy link
Member

v14.2.4 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

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

Successfully merging a pull request may close this issue.

2 participants