Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Passing interface type to object parent

Im trying to pass the interface type to a Object returning jsx components, but i dont want to explicitly specify the type for each component. how can i do this.

->>>

interface blockProps {
  children: any;
}

const block: blockProps = {
  h1: ({ children }: any) => (
    <h1 className="my-3 text-6xl font-bold md:text-8xl md:my-4">{children}</h1>
  ),
  h2: ({ children }: any) => (
    <h2 className="my-3 text-5xl font-bold md:text-7xl md:my-4">{children}</h2>
  ),
  h3: ({ children }: any) => (
    <h3 className="my-3 text-4xl font-bold md:text-6xl md:my-4">{children}</h3>
  ),
  h4: ({ children }: any) => (
    <h4 className="my-3 text-3xl font-bold md:text-5xl md:my-4">{children}</h4>
  ),
  blockquote: ({ children }: any) => (
    <blockquote className="relative p-4 my-8 text-xl italic border-l-4 bg-neutral-100 text-neutral-600 border-neutral-500">
      <p>{children}</p>
    </blockquote>
  ),
};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can define your types like this:

type possibleTags = 'h1' | 'h2' | 'h3' | 'h4' | 'blockquote';

interface blockProps {
  children: any;
}

type blockMap = {
  [key in possibleTags]: (props: blockProps) => React.ReactElement<any, any>;
};

I had a little fun and here :): https://stackblitz.com/edit/react-ts-xj27j6?file=index.tsx

about 4 years ago · Juan Pablo Isaza Report

0

interface Blocks {
 [key: string]: (props: { children: ReactNode }) => JSX.Element
}

const block: Blocks = {
 // ...
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!