Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
Types not matching up when using a function to render a component

Here's a simplified component code:

type Props = (DropdownType | TextType | NumberType | ColorType | CheckboxType) &
  SharedType;

const Component: FC<Props> = (_props): ReactElement => {
  return <></>;
};

type Args = TextType | NumberType | DropdownType | CheckboxType | ColorType;
export const generateComponent = (args: Args): ReactElement => {
  return (
    <Component label="label" name="name" {...args}>
      {args.children}
    </Component>
  );
};

Here are the types:

type SharedDisplayAndEditTypes = {
  label: string;
};

export type SharedType = SharedDisplayAndEditTypes & {
  required?: boolean;
  validationMessage?: string;
  name: string;
  disabled?: boolean;
};

export type TextType = {
  type: "text";
  children: string;
};

export type NumberType = {
  type: "number";
  children: number;
};

export type DropdownType = {
  type: "dropdown";
  options: string[];
  children: string;
};

export type ColorType = {
  type: "color";
  children: string;
};

export type CheckboxType = {
  type: "checkbox";
  children: boolean;
};

And here's the codesandbox

I am trying to create a function, which renders my component (for tests. This is a simplified example). I thought that if I just kind of mash together the props and args it'll all work fine, but obviously, I'm missing something, but am not sure what.

The error I'm getting is similar to the sandbox example:

Types of property 'children' are incompatible.
    Type 'string | number | boolean' is not assignable to type 'string & ReactNode'.
      Type 'number' is not assignable to type 'string & ReactNode'

Basically the types don't add up, and I have no idea why, since I'm not using ReactNode anywhere as a prop type

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok, fixed it like so:

export const generateComponent = (args: Args): ReactElement => {
  return <Component label="label" name="name" {...args} />;
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda