From TypeScript Types to Language Design: Paradigms and Engineering Trade-offs

February 20, 2025

Having worked with Java, Haskell, C, and JavaScript, I had encountered several ways to describe data and organize behavior. One day, I became curious about TypeScript's type, interface, and class. The names looked familiar, but did they mean the same things as the concepts I already knew?

My initial notes collected a comparison of those three declarations. As I revisited the question, I became more interested in what sits behind the syntax: why language designers choose particular mechanisms, which programming styles those mechanisms encourage, and how engineering requirements shape the result.

A language can absorb ideas from object-oriented and functional programming without adopting every convention associated with either. To understand that combination, I find it more useful to ask what each mechanism accomplishes than to assign the whole language a single paradigm label.

The examples below are small teaching examples, not reconstructions of production code. Similarities between languages are comparisons unless a cited design document establishes a historical motivation.

Start with the question a declaration answers

The article collected in my original notes makes a useful observation:

“换句话说,type 不需要运行时信息。”

In other words, type does not require runtime information. — My translation of Lee_Chen86 (2023), section “1. type.”1

That is a starting point, but it does not fully explain how to choose a declaration. I would separate three questions:

DeclarationMain question in this comparisonRuntime consequence
typeWhat type expression should this name denote?The alias itself is erased.
interfaceWhat structure must a compatible value provide?The declaration itself is erased.
classHow are instances constructed and their behavior implemented?The constructor and implemented behavior remain as JavaScript code.

A class also introduces an instance type. However, its type annotations do not survive as automatic runtime validation. implements checks a relationship; it does not supply the methods being promised.23

Quick Q&A: the questions I searched for

My searches at the time included “typescript 怎么定义一个对象类”, “typescript 用class还是interface”, and “TYPESCRIPT CREATE OBJECT BY INTERFACE”. I also wanted to understand why I would choose a class over an interface, and how the distinction related to the OOP languages I already knew. These are natural starting questions; here are the short answers before the deeper comparisons.

How do I define an object or a class in TypeScript?

An object is a value. An interface can describe its expected shape, while an object literal creates the value:2

interface UserProfile {
  name: string;
}

const profile: UserProfile = { name: "Ada" };

To define a class and construct an instance, I can write:

class UserAccount implements UserProfile {
  name: string;

  constructor(name: string) {
    this.name = name;
  }

  greet(): string {
    return `Hello, ${this.name}`;
  }
}

const account = new UserAccount("Ada");
account.greet(); // "Hello, Ada"

Here, UserAccount supplies the constructor and method implementation. implements UserProfile checks that its instances satisfy the interface.3

Can I create an object by interface?

I can create an object that satisfies an interface, as profile does above. The interface itself supplies no constructor: new UserProfile() would be a compile-time error. The object literal performs the creation; the annotation asks the compiler to check its shape. Writing {} as UserProfile would not fill in the missing name field either.2

Should I use class or interface?

For a settings object, a function parameter, or a description of data, an interface is often sufficient; a type alias can describe the same object shape. For objects built through a shared constructor with associated methods, a class can be useful. This is a design choice about how to create and organize values. Plain objects and factory functions can also carry behavior.23

Why use a class rather than an interface? Can I use both?

A class supplies executable construction and method code; an interface supplies a compile-time contract. In the example, I could expose either value through that contract:

function showName(user: UserProfile): string {
  return user.name;
}

showName(profile);
showName(account);

The caller only needs name. It can accept both the plain object and the class instance. The interface does not generate greet() or initialize fields; I write that implementation in the class.3

Is this the same interface/class distinction I learned in OOP?

The contract/implementation distinction is familiar, but OOP languages differ in how they establish compatibility. In Java, implementing an interface requires a declared relationship, possibly inherited. In TypeScript, a compatible structure is enough: removing implements UserProfile from this example would still let showName(account) type-check. Keeping it makes my intent explicit and checks the class declaration. The later interface section explores this difference in more detail.45

These answers resolve the immediate syntax questions. They also lead to the larger question I wanted to explore: what guarantees does each declaration actually provide?

Does a new name create a new type?

Consider two domain names:

type UserId = string;
type OrderId = string;

const orderId: OrderId = "order-42";
const userId: UserId = orderId; // Accepted: both aliases denote string.

These names communicate intent, but they do not establish separate identities. TypeScript's handbook is explicit:

Note that aliases are only aliases - you cannot use type aliases to create different/distinct “versions” of the same type.

— TypeScript, Everyday Types, “Type Aliases.”2

This reminds me of C's typedef: naming an existing type does not itself create a distinct type. A declaration that also introduces a new struct is a different case; the structure declaration, not the aliasing operation, introduces that type.6

Haskell makes another distinction visible:

type UserName = String
newtype CustomerId = CustomerId String

The first is a synonym. The second introduces a distinct type with a constructor while retaining the underlying representation. Haskell's data declaration is another mechanism, used to introduce algebraic data types. These are not interchangeable spellings.7

The engineering question is therefore whether a name is documentation or a boundary the compiler must enforce. When accidental interchange is costly, an alias alone is insufficient. TypeScript projects sometimes use branded types or wrappers for this purpose, but that adds a construction discipline; it does not make arbitrary incoming strings trustworthy.

Expressing alternatives: a connection to functional programming

An operation may succeed or fail. Instead of allowing unrelated optional fields, describe the valid alternatives:

type ParseResult =
  | { kind: "success"; value: number }
  | { kind: "failure"; message: string };

function describeResult(result: ParseResult): string {
  switch (result.kind) {
    case "success":
      return `Parsed ${result.value}`;
    case "failure":
      return result.message;
    default: {
      const unreachable: never = result;
      return unreachable;
    }
  }
}

The literal kind distinguishes the cases, allowing TypeScript to narrow the type. Assigning the remaining case to never makes an omitted variant a compile-time error when this function is checked.8

Haskell gives a related example a different representation:

data ParseResult
  = Success Double
  | Failure String

Both examples describe alternatives, but TypeScript uses structurally typed JavaScript objects and ordinary control flow. Haskell introduces named constructors through a datatype declaration. The analogy is useful without claiming that the languages have identical semantics.7

C's union is another misleadingly familiar word. It describes overlapping storage, not an automatically checked collection of tagged cases. A C program can pair a union with an explicit tag, but keeping the tag and stored member consistent requires additional discipline.6

TypeScript intersections answer a different question. A | B means a value may satisfy either alternative; A & B requires both constraints. An intersection does not combine object implementations or copy methods at runtime. Incompatible constraints can leave no possible value for a property.2

This is a practical benefit often associated with functional programming: describe the valid data cases before writing operations over them. Using that technique does not require the surrounding application to abandon objects or mutation entirely.

Interfaces: explicit affiliation or compatible structure?

Java taught me to associate an interface with a declared implementation relationship. A class participates through its declared type hierarchy, directly or through inheritance; merely having methods with matching signatures is not enough.4

TypeScript allows a different relationship:

interface Formatter {
  format(value: number): string;
}

const decimalFormatter = {
  format(value: number): string {
    return value.toFixed(2);
  },
};

function display(value: number, formatter: Formatter): string {
  return formatter.format(value);
}

display(12.5, decimalFormatter);

The object needs no declaration that it implements Formatter. Its structure satisfies the requirement. This is static structural compatibility, not runtime validation of an unknown object. TypeScript also has qualifications such as excess-property checks and special compatibility rules for private and protected class members.5

An interface can extend another interface; a class can implement it. A type alias can also describe an object, so neither “all objects need interfaces” nor “interfaces only belong to classes” is a useful rule. One meaningful difference is that interfaces support declaration merging, while an alias cannot be reopened in the same way.2

Haskell's type classes add another possible naming trap. They organize overloaded operations through class and instance declarations; they are not JavaScript classes with constructors and mutable instance fields.7 The shared word “class” should not substitute for examining the actual compatibility and execution rules.

What remains when the types disappear?

A TypeScript class provides an implementation as well as an instance type:

class FixedFormatter implements Formatter {
  private readonly digits: number;

  constructor(digits: number) {
    this.digits = digits;
  }

  format(value: number): string {
    return value.toFixed(this.digits);
  }
}

const fixed = new FixedFormatter(2);
display(12.5, fixed);

The constructor, stored value, and method participate in execution. Formatter, the parameter annotations, and the implements check do not turn into validators. The emitted code depends on the compiler target, but there is still runtime behavior to construct and call.3

It would therefore be inaccurate to say that a class preserves all its type information. It preserves its implementation. Likewise, TypeScript's private modifier should not be confused with JavaScript's runtime-enforced #private fields.3

This distinction matters at system boundaries. An assertion such as incoming as ParseResult does not inspect a server response. External data needs runtime checks before it can safely be treated as that type. Static reasoning about trusted values and validation of untrusted values are complementary jobs.2

Paradigms become useful through concrete mechanisms

Object-oriented programming is not synonymous with a deep inheritance tree. Functional programming is not synonymous with replacing every loop with map. For this comparison, I focus on smaller mechanisms and their consequences:

MechanismEngineering useQuestion it leaves open
Encapsulated objectsKeep related state and operations behind an interface.Who owns the object, and who can observe its mutations?
First-class functionsPass behavior directly and compose transformations.Does the function depend on hidden mutable state or effects?
Immutable data and pure transformationsMake local reasoning and repeatable tests easier.How are I/O and necessary state changes represented?
Tagged alternativesMake distinct states explicit.How are external values checked and new variants handled?
Interface-based polymorphismDecouple callers from particular implementations.Is compatibility declared, structural, or established another way?

These mechanisms can coexist, but their guarantees differ. A TypeScript function can mutate global state; a readonly annotation does not deeply freeze a runtime object. Haskell places purity and non-strict evaluation much closer to its language foundations. Borrowing a useful data-modeling technique from Haskell does not give TypeScript the rest of that semantic model.9

My engineering interpretation is that the unit of comparison should be the mechanism and its constraints. Paradigm names are useful background, but too broad to settle a design decision on their own.

A design pattern can become a function—or remain an object

Suppose a caller needs a replaceable fee policy. An object-based representation is straightforward:

interface FeePolicy {
  fee(amount: number): number;
}

class PercentageFee implements FeePolicy {
  constructor(private readonly rate: number) {}

  fee(amount: number): number {
    return amount * this.rate;
  }
}

function totalWithPolicy(amount: number, policy: FeePolicy): number {
  return amount + policy.fee(amount);
}

This resembles Strategy: the calculation depends on a replaceable behavior. For one operation with little state, a function can express the same substitution point:

type FeeFunction = (amount: number) => number;

const percentageFee = (rate: number): FeeFunction =>
  amount => amount * rate;

function totalWithFunction(amount: number, fee: FeeFunction): number {
  return amount + fee(amount);
}

const objectTotal = totalWithPolicy(100, new PercentageFee(0.05));
const functionTotal = totalWithFunction(100, percentageFee(0.05));

Both produce 105 in this teaching example. A real monetary calculation would also need an explicit rounding and numeric-representation policy.

The important invariant is replaceable behavior. The class is useful when identity, coordinated operations, or a lifecycle becomes meaningful. A function is convenient when a single transformation is sufficient. A closure can also carry state, so the distinction cannot be reduced to “objects have state; functions do not.”

This example illustrates how language facilities change the amount of machinery needed to express a pattern. It is not evidence that TypeScript's designers introduced first-class functions to implement Strategy: JavaScript already supplies those functions, and a historical influence claim would need separate evidence.

TypeScript's engineering constraint: work with JavaScript

The design goals provide a stronger basis for understanding TypeScript than an analogy with Java or Haskell alone:

“Use a consistent, fully erasable, structural type system.”

— Microsoft, TypeScript Design Goals, goal 9.10

The same document emphasizes preserving JavaScript's runtime behavior and avoiding runtime overhead. It explicitly declines to reproduce another language exactly, and treats a fully sound type system as a non-goal in favor of a practical balance.10

That does not mean type checking is unimportant. It explains a constraint on how the language can help: existing JavaScript patterns and libraries must remain usable. Describing object shapes and callable values fits that setting; forcing every value into a new nominal class hierarchy would solve a different problem.

My reading is that TypeScript's mixture is deliberate adaptation to an existing runtime and ecosystem. The goal is not to transplant all of one paradigm's guarantees. It is to add useful static descriptions and tooling while respecting the environment in which programs already run.

Go as a contrasting example of engineering-led selection

Go provides a useful comparison because its designers explicitly discuss engineering goals. Rob Pike writes:

“Software engineering guided the design of Go.”

— Pike (2012), section 19, opening sentence.11

His account connects the language to Google's large codebases, build delays, dependency problems, and concurrent networked systems. Concurrency and garbage collection are only part of that story; predictable dependencies and maintainability across large teams also matter.11

Go's treatment of object-oriented ideas illustrates selective adoption. It has types, methods, and interfaces without a conventional class-inheritance hierarchy. A type can satisfy an ordinary interface through its method set without declaring that relationship. Embedding supports composition and method promotion, but it is not equivalent to subclassing.12

That resembles TypeScript's structural compatibility in one respect: explicit affiliation is not always required. But Go's interface values and method-set rules are not TypeScript's erased object-shape declarations. Similar engineering benefits do not make the mechanisms interchangeable.

Go also demonstrates that simplicity is a design judgment that can evolve. It added type parameters in Go 1.18 in 2022. Calling Go “the language without generics” would freeze one historical phase into a permanent identity.13 The interesting question is how an added abstraction fits the rest of the language and addresses recurring needs.

I would not describe this as Go combining every advantage of OOP and functional programming. Its example is more specific: a language can select interfaces, composition, functions, concurrency facilities, and automatic memory management according to its intended workload rather than allegiance to one paradigm.

Evaluate the combination against the engineering goal

The following is my framework for reading language designs, not a claim that every designer followed this exact process.

First, identify the expensive problem. Is it accidental mixing of domain values, tangled dependencies, unsafe resource handling, slow builds, difficult state reasoning, or migration from existing code? Different answers justify different mechanisms.

Next, identify what the mechanism guarantees. An alias may improve readability without preventing interchange. An interface may enforce structure without checking runtime input. A function parameter may simplify substitution without guaranteeing purity. A class may encapsulate state without making concurrent access safe.

Then examine interactions. Adding inheritance, structural compatibility, mutable state, generics, and runtime reflection introduces questions at their boundaries. More expressive pieces do not automatically form a language that is easier to learn, implement, or maintain.

Finally, account for the surrounding system: libraries, compiler diagnostics, build tools, deployment constraints, and team experience. A feature can be elegant in isolation yet expensive to introduce into a working ecosystem.

The relationship is a feedback process: recurring engineering problems encourage idioms and patterns; languages can make some of them easier to express; those mechanisms then change how later programs are designed. Whether a particular feature actually arose from a particular pattern remains a historical question, not something syntax alone can prove.

Returning to type, interface, and class

I started by asking which keyword to use. I now find a better set of questions: am I naming a type expression, describing a compatible structure, representing alternatives, or implementing runtime behavior? What must the compiler reject, and what must the program still check while running?

Those questions connect my experience with C, Java, Haskell, and JavaScript without flattening their differences. They also leave room to mix techniques deliberately: data variants for meaningful states, functions for transformations, and objects for behavior and lifecycle where those are useful. The engineering goal determines the combination.

References

Footnotes

  1. Lee_Chen86. (2023, May 7). 深入理解 TypeScript 的 type 以及 type 与 interface 和 class 的区别 [Understanding TypeScript's type and its differences from interface and class]. [Blog post]. CSDN. https://blog.csdn.net/chencl1986/article/details/130541697 ↩

  2. TypeScript. (n.d.). Everyday types. TypeScript Handbook. Retrieved February 20, 2025, from https://www.typescriptlang.org/docs/handbook/2/everyday-types.html ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8

  3. TypeScript. (n.d.). Classes. TypeScript Handbook. Retrieved February 20, 2025, from https://www.typescriptlang.org/docs/handbook/2/classes.html ↩ ↩2 ↩3 ↩4 ↩5 ↩6

  4. Oracle. (2023). The Java language specification, Java SE 21 edition: Interfaces. Chapter 9. https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html ↩ ↩2

  5. TypeScript. (n.d.). Type compatibility. TypeScript Handbook. Retrieved February 20, 2025, from https://www.typescriptlang.org/docs/handbook/type-compatibility.html ↩ ↩2

  6. GNU Project. (n.d.). GNU C language manual. Sections on typedef names and unions. Retrieved February 20, 2025, from https://www.gnu.org/software/c-intro-and-ref/manual/c-intro-and-ref.html ↩ ↩2

  7. Marlow, S. (Ed.). (2010). Haskell 2010 language report: Declarations and bindings. Sections 4.2 and 4.3. https://www.haskell.org/onlinereport/haskell2010/haskellch4.html ↩ ↩2 ↩3

  8. TypeScript. (n.d.). Narrowing. TypeScript Handbook. Retrieved February 20, 2025, from https://www.typescriptlang.org/docs/handbook/2/narrowing.html ↩

  9. Marlow, S. (Ed.). (2010). Haskell 2010 language report: Introduction. https://www.haskell.org/onlinereport/haskell2010/haskellch1.html ↩

  10. Microsoft. (n.d.). TypeScript design goals. TypeScript project wiki. Retrieved February 20, 2025, from https://github.com/microsoft/TypeScript/wiki/TypeScript-Design-Goals ↩ ↩2

  11. Pike, R. (2012, October 25). Go at Google: Language design in the service of software engineering. Adapted from a SPLASH 2012 keynote. https://go.dev/talks/2012/splash.article ↩ ↩2

  12. The Go Authors. (n.d.). Frequently asked questions. Sections on object-oriented programming and type inheritance. Retrieved February 20, 2025, from https://go.dev/doc/faq ↩

  13. The Go Team. (2022, March 15). Go 1.18 is released! The Go Blog. https://go.dev/blog/go1.18 ↩

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-02-20). From TypeScript Types to Language Design: Paradigms and Engineering Trade-offs. https://caiborui.com/blog/2025-02-20-en-typescript-types-and-language-design

@misc{borui2025-86b68a74,
  author = {borui},
  title = {{From TypeScript Types to Language Design: Paradigms and Engineering Trade-offs}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-02-20-en-typescript-types-and-language-design}
}