1
type subProp = {
  id: string,
  name: string
};

type ParentProps = {
  subscriptions?: [
    {
      id: string,
      items: [???Array Of subProp???]
    }
  ]
}

Is this case doable in typescript with only type alias? If so, how to do it? I can't find any viable option online. If no, what's the alternative?

1 Answer 1

2

You can declare items as an array of subProps and subscriptions as an array of a type with id and items:

type subProp = {
  id: string,
  name: string
};

type ParentProps = {
    subscriptions?: {
        id: string,
        items: subProp[];
    }[];  
}
Sign up to request clarification or add additional context in comments.

2 Comments

what is this XXX[ ] syntax calls? I want to look into it and learn more! thanks
It just means that it's an array of type XXX. Another way to do this is: items: Array<subProp>, see: typescriptlang.org/docs/handbook/basic-types.html#array and stackoverflow.com/questions/36842158/…

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.