0

I have to create a shape interface that has four field three numbers and a view I think i can do this with two interfaces and extending the one ,the view i need to be able to be undefined as all shapes dont always have a view. The view itself has properties indexShape , height , and moveToFront . Since every shape is not displayed on every level, the view may be undefined I have the below code but i am unsure if this is the correct way?? any help would be appreciated new to typescript

    interface view{
    indexShape?:any;
    height?:number;
    moveToFront?:any;
}

interface shape extends view{
numerator: number;
denominator: number;
dropZone: number;

};
1
  • interface that has four field three numbers and a view Missing mapping of view, I guess. Also, if you extend, you are inheriting all properties. This is helpful when view can be inheritted to more than one shape interface. If not, I'd suggest IShape { view?: view; ... }. Also note I infront of interface name. That is a good convention. So it should be interface IShape extends IView Commented Mar 18, 2019 at 16:36

1 Answer 1

1

all shapes dont always have a view.

So, there is no inheritance.

interface View {
  indexShape: any;
  height: number;
  moveToFront: any;
}

interface Shape {
  view?: View;
  numerator: number;
  denominator: number;
  dropZone: number;
}
Sign up to request clarification or add additional context in comments.

1 Comment

@mKalita I'm happy to help. Do not forget to validate my answer.

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.