Skip to content

Improve types for TestModuleMetadata #51765

Closed
@Christian24

Description

@Christian24

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions