Understanding Type Checking: A Comparison of TypeScript, .NET, and Java

A comparison of type checking options in TypeScript, .NET, and Java.

Understanding Type Checking: A Comparison of TypeScript, .NET, and Java

Comparison of Type Checking Options

FeatureTypeScript.NET (C#)Java
Static TypingYesYesYes
Dynamic Typing

Yes (with any type)

NoNo
Union Types

Yes (type A = B | C)

NoNo
Intersection Types

Yes (type A = B & C)

NoNo
Optional Types

Yes (type A = B | undefined)

Yes (nullable types, T?)

Yes (with Optional<T>)

Type InferenceYesYesLimited
GenericsYesYesYes
Type Aliases

Yes (type A = B)

No (use classes/interfaces instead)No (use classes/interfaces instead)
InterfacesYesYesYes
EnumsYesYesYes
Structural TypingYesNo (nominal typing)No (nominal typing)
Nominal TypingNoYesYes
Type Guards

Yes (typeof, instanceof)

Yes (is, as)

Yes (instanceof)

Type Casting

Yes (as keyword)

Yes ((Type)variable)

Yes ((Type)variable)

Type Annotations

Yes (let x: Type)

Yes (Type x)

Yes (Type x)

Type CheckingCompile-timeCompile-timeCompile-time
Nullable Types

Yes (type A = B | null)

Yes (T? or Nullable<T>)

Yes (Optional<T>)

Related Articles