Declaring string type with min/max length in typescript

You can achieve this using a type constructor and something called a “Phantom Type” (read a nice article about this here) which is a technique to ensure that a type can not be assigned to a value directly. Here’s an example of a StringOfLength<Min,Max> type using these techniques: type StringOfLength<Min, Max> = string & { … Read more

Why use generic constraints in C#

You ask, “can’t I switch ALL references of T in this class with ISomething?” So I think you mean to compare: public class MyClass<T> where T : ISomething { public T MyProperty { get; set; } } With: public class MyClass { public ISomething MyProperty { get; set; } } In the second example, MyProperty … Read more