Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
C# 11–12 and .NET 7–8: Generic Math, Frozen and Collection Expressions
The generic sum you couldn't write in C# 10, generic math with static abstract members and INumber<T>; FrozenDictionary and FrozenSet, built once and read many times, measured with BenchmarkDotNet; square-bracket collection expressions, spread and CollectionBuilder.
Generic Variance in C#: Covariance and Contravariance (in and out)
Why can't a List<EBook> be a List<Book> when it can be an IEnumerable<Book>? The hole in array covariance, covariance with out, contravariance with in, variance in delegates, the limits of the rules and the cast trap CS0266 suggests.
Generic Classes, Generic Methods and Constraints in C#
Writing your own generic classes and methods: paging with Page<T>, the limits of type inference, default and the unconstrained T? trap. The class, struct, new(), notnull, unmanaged and Enum constraints with real compiler errors; per-closed-type statics and the == trap in generic code.
Why C# Has Generics: ArrayList, Boxing and Type Safety
The price of ArrayList storing everything as object: InvalidCastException pushed to run time, boxing of value types and eight times the memory. Type safety with List<T>, how the runtime sees generic types, and bringing old collections into the generic world with OfType and Cast.
TypeScript Indexed Access Types: Deriving Types from Existing Ones with T["key"]
We look at reading a property's type with T["key"], union indexes, getting an array's element type with T[number], T[K] in generics and deriving pieces from large API types.
Generic Interfaces, Types and Classes in TypeScript: Box, Result and Stack
We move type parameters from functions to types: Box<T> as a generic type alias, a paginated list as a generic interface, Result<T, E> for success and failure, and generic Stack and Registry classes.
Generic Constraints in TypeScript: extends, Default Types, const and NoInfer
We constrain type parameters with extends, tie two parameters together with keyof, use default type parameters, and steer inference with TS 5.0 const type parameters and TS 5.4 NoInfer.
Introduction to Generics in TypeScript: Taking the Type as a Parameter
Why generic functions exist, how a type parameter ties input to output, how TypeScript infers T, and how generics differ from any and unknown, with small examples.