Can I (somehow?) forbid the skipping of optional parameter in typescript?
class MyList {
constructor(
public head?: number,
public tail?: MyList
){}
}
const L0 = new MyList(); // <--- empty element list - good !
const L1 = new MyList(888); // <--- single element list - good !
const L2 = new MyList(777, L0); // <--- general list - good !
const L3 = new MyList(undefined, L1); // <--- forbid this
I want to statically enforce the following property on my list:
- If
head
isundefined
thentail
is alsoundefined
(and the list is empty)
Any TypeScript trick to achieve that? (This question is complementary to this question)