If I have a triangle class, like so:
export default class Triangle {
sides: number[]
constructor(...sides: number[]) {
this.sides = sides
}
kind() {
// returns type of triangle
{
}
and if the sides passed into the constructor do not create a real triangle, is it better to throw the error when the class is created (e.g. in the constructor), or when the function(s) are called?
There is this answer, that says it's okay in Java, and I'm sure it works in TypeScript. I'm just wanting to know if there are "best practices" in regards to OOP in general and TypeScript specifically.