Next.js Discord

Discord Forum

Mixing Read only and Normal Props

Unanswered
WhyFencePost posted this in #help-forum
Open in Discord
I have a deceleration of an object which uses children as a ReadOnly item, but I need to add a boolean that is not read only. How do I do this?
function VerticalCardWrapper({
    children,
    title,
    description,
    noBack,
    noForward,
}: Readonly<{
    children?: React.ReactNode,
    title : string,
    description : string,
    noBack? : boolean,
    noForward? : boolean,
}>) {

3 Replies

Props should NOT be mutated, which means they're supposed to be Readonly anyway. But if you want to...
type Props = Readonly<{
  children?: React.ReactNode;
  // choose which ones go here
}> & {
  // choose which ones go here
  noBack?: boolean;
  noForward?: boolean;
  title: string; 
  description: string;
};

function VerticalCardWrapper(props: Props) {

Btw this only seems to work if props aren't destructured..