Skip to content

Improve types for TestModuleMetadata #51765

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

Closed
Christian24 opened this issue Sep 13, 2023 · 2 comments
Closed

Improve types for TestModuleMetadata #51765

Christian24 opened this issue Sep 13, 2023 · 2 comments

Comments

@Christian24
Copy link

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Hello,

I wish TestModuleMetadata were typed a little more. I have seen something along the lines of:

await TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
      providers: [{provide: MyService, usevalue: myMock}]
    }).compileComponents();

useValue isn't written correctly, there is no error in the static code analysis, because the actual type is just any[].

Proposed solution

Maybe we can change it to something like:

export interface ProviderInterface {
  provide: any;
  useValue: any;
  multi?: boolean;
}
... TestModuleMetadata
imports?: Array<Type<any>|ModuleWithProviders<unknown>|any[]>;
providers?: Array<ProviderInterface | TypeProvider | EnvironmentProviders>;
componentProviders?: Array<ProviderInterface | TypeProvider | EnvironmentProviders>;

This would still allow people to pass any mock for providers they want, but we would help them get the structure for the provider correctly.

Alternatives considered

None

JeanMeche added a commit to JeanMeche/angular that referenced this issue Sep 13, 2023
To improve compiler errors on `TestModuleMetadata`, lets replace `any`  for `providers`, `declarations` and `imports`

fixes angular#51765
JeanMeche added a commit to JeanMeche/angular that referenced this issue Sep 13, 2023
To improve compiler errors on `TestModuleMetadata`, lets replace `any`  for `providers`, `declarations` and `imports`

fixes angular#51765
JeanMeche added a commit to JeanMeche/angular that referenced this issue Sep 13, 2023
To improve compiler errors on `TestModuleMetadata`, lets replace `any`  for `providers`, `declarations` and `imports`

fixes angular#51765
JeanMeche added a commit to JeanMeche/angular that referenced this issue Sep 13, 2023
To improve compiler errors on `TestModuleMetadata`, lets replace `any`  for `providers`, `declarations` and `imports`

fixes angular#51765
JeanMeche added a commit to JeanMeche/angular that referenced this issue Sep 13, 2023
To improve compiler errors on `TestModuleMetadata`, lets replace `any`  for `providers`, `declarations` and `imports`

fixes angular#51765
@AndrewKushnir
Copy link
Contributor

FYI, closing this ticket as a duplicate of #37178.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants