What is a Superset (in programming?)

Shaundai Person
AuthorShaundai Person

When it comes to programming languages, you can think of supersets as upgrades.

A superset is a language that includes all of the features of another language, as well as additional features.

For example, Kotlin is a superset of Java, C++ is (mostly) a superset of C, and TypeScript is a superset of JavaScript.  The opposite of a superset is a subset.

What’s the benefit of supersets?

Supersets are often created to add new features to an existing language, or to make a language more modern, easier to use, or help users to target a specific domain.  TypeScript adds functionality to JavaScript, including:

Early error detection

TypeScript is a statically typed language, which means that it does type checking at compile time. This allows users to see errors right in their IDE as they are coding, preventing them errors from making it into production!

Code consistency

TypeScript enforces stricter rules than JavaScript, ensuring consistency across all code contributed to the codebase.

Scalability

Type annotations in TypeScript act as documentation in your code, making it easier for other developers to read and understand your code and onboard onto your codebase quickly. TypeScript’s stricter rules also lead developers to write better, cleaner code that remains organized and well-documented as the codebase continues to scale.

Tooling

TypeScript has a rich ecosystem of tools (including editors, linters, and debuggers) which can help developers to write better, more resilient code efficiently and debug more quickly.

Supersets are useful for developers who want to use the features of a language they’re already familiar with, but also want to take advantage of enhancements that improve the developer experience. Supersets are also useful for organizations that want to gradually migrate their code from one language to another.

If we have supersets, why do we need to keep subsets?

Having a superset doesn’t mean that its subset is no longer necessary!  Many organizations have a significant amount of legacy code written in older languages or subsets.  Maintaining and updating this code can be easier if subset-specific tools and resources are available.  Subsets provide backward compatibility, which is crucial for organizations with a large investment in existing code or when migrating from one language to another gradually.  Subsets are also often simpler and more performant than their supersets because they have fewer features.

TypeScript cannot actually exist without JavaScript.

TypeScript is built on top of JavaScript, and it relies on JavaScript for its core functionality.  In fact, your browser can’t actually read TypeScript! Your TypeScript is compiled into JavaScript so that your browser can parse it.

💡 There is currently an active TC39 proposal to add type annotations into JavaScript itself! The proposal aims to enable developers to run programs using JavaScript supersets such as TypeScript without transpilation. Learn more here.

TypeScript is a powerful superset of JavaScript that was created to provide a range of benefits for developers, including earlier error detection, stricter code consistency, scalability, and a rich ecosystem of tools. While subsets like JavaScript are still important for maintaining legacy code and providing backward compatibility, TypeScript makes a great upgrade for organizations that are ready to scale their applications.

Share this article with your friends

Shaundai Person
Written by Shaundai Person

Senior Software Engineer at Netflix.

Join 40,000+ developers in the Epic Web community

Get the latest tutorials, articles, and announcements delivered to your inbox.

I respect your privacy. Unsubscribe at any time.