0

I have two interfaces:

Interface 1:

interface ILineItemProps {
    state: 'OPENED' | 'COMPLETED' | 'CANCELLED' | 'PENDING';
}

Interface 2:

interface IProps {
    steps: [
        {
            key: string;
            title: string;
        }
    ];
}

Interface 1 must add its object, in this case the state, inside the object of interface 2, thus:

[{
key: string;
title: string;
state: interface1
}]

I've tried it in several ways:

[{
key: string;
title: string;
} & Interface1]

Array<{
key: string;
title: string;
} & Interface1>

But I could not.

2
  • did you try to push() it? or seperate inside the array with comma instead of &? Commented Dec 29, 2021 at 17:52
  • Does this answer your question? Commented Dec 29, 2021 at 17:55

1 Answer 1

0

Try this:

interface ILineItemProps {
  state: 'OPENED' | 'COMPLETED' | 'CANCELLED' | 'PENDING';
}

type Step = {
  key: string;
  title: string;
} & ILineItemProps;

interface IProps {
  steps: Step[];
}

// test:

const iProps = {
  steps: [] as Step[],
};

iProps.steps.push({
  key: 'a',
  title: 'b',
  state: 'OPENED',
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.