skip to Main Content
const componentMapper = {
  input: InputComponent,
  button: ButtonComponent,
  select: SelectComponent,
  date: DateComponent,
  radiobutton: RadiobuttonComponent,
  checkbox: CheckboxComponent,
  switch: SwitchComponent,
  textarea: TextAreaComponent
};
const compFactory = this.resolver.resolveComponentFactory(componentMapper[this.field.type]);

What is strict type for const compFactory

2

Answers


  1. The type of compFactory is

    ComponentFactory<
      typeOf InputComponent
      | typeOf ButtonComponent
      | ...
      | typeOf SwitchComponent
      | typeOf TextAreaComponent
    >
    
    Login or Signup to reply.
  2. Since there can be multiple component, best to go for any type. Since its more readable.

    const componentMapper: { [key: string]: any } = {
      child: Child,
    };
    

    Stackblitz Demo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search