EnriqueMark
Design Patterns & Architecture

Inheritance and constraints

2026-03 English

This part is kind of interesting, inheritance and constraints seem to overlap a little, and when you get down to it, inheritance itself also means inheriting the structure itself, which is essentially a constraint. It’s just that ts is more flexible, it’s duck typing, so matching structure is enough, but in C# it has to be inheritance.

// TypeScript
// extends here implies inheritance, but matching structure passes the check too
function foo<T extends JobBase<T>>() {}

// C# equivalent
// but here it has to be inheritance
void Foo<T>() where T : JobBase<T> {}

Translation note. I wrote this in Chinese. This English version is an LLM translation, so the wording is not mine even though the thinking is. Original: 继承和约束.