Urgent.News

What's breaking now, across hundreds of outlets.

Tech

TypeScript: Do you know the differences between type and interface?

They look almost identical, but there are some important differences. Let's explore when to use each. When defining the shape of an object in TypeScript, we generally have two options: type and interface . Let's start with a simple example: type Person = { name : string ; age : number ; } ; // Using an interface interface Person { name : string ; age : number ; } Both approaches describe an…

TypeScript offers two primary ways to define object shapes: type and interface . While they appear similar, there are key differences to consider when choosing one over the other.

Both type and interface describe an object with the same properties. For instance:

type Person = { name : string ; age : number ; }

interface Person { name : string ; age : number ; }

However, one notable difference arises when introducing extra properties. With both type and interface, TypeScript raises an error for excess properties, known as an excess property check. This is a crucial distinction between the two.

Interestingly, interfaces can extend other interfaces, whereas type aliases cannot. For example:

interface Employee extends Person { salary : number ; }

Likewise, an interface can be extended by a type using intersection types:

interface Person { name : string ; age : number ; }

type Employee = Person & { salary : number ; }

Another point of differentiation is the ability to union types with type aliases. Type aliases can combine unions and intersections, offering greater flexibility. For instance:

type StringOrNumber = string | number;

type InputOrOutput = ( Input | Output ) & { name : string ; }

In contrast, interfaces lack union type syntax. Attempting to extend an interface with a union type results in an error.

Declaration merging is another area where interfaces shine. Unlike type aliases, interfaces can be merged together seamlessly. Consider this scenario:

interface Person { name : string ; age : number ; }

interface Person { city : string ; }

The TypeScript compiler merges both declarations into a single interface, allowing access to all properties defined. This declaration merging capability proves useful for extending third-party library declarations, augmenting global interfaces, or creating extensible public APIs. However, it's essential to use declaration merging judiciously to avoid unintended consequences.

So, which should you choose? Type or interface? Ultimately, the decision depends on your specific needs and project requirements. Consistency within your codebase is key. If your existing project primarily uses interfaces, it makes sense to stick with that convention. Conversely, if you frequently need unions, intersections, or declaration merging, type aliases might be a better fit.

For new projects, consider whether declaration merging is a requirement. If so, interface might be the ideal choice, particularly when defining object contracts that allow library consumers to augment your public declarations. On the other hand, if you primarily need unions, intersections, or more advanced type compositions, type aliases are likely the better option.

Ultimately, both type and interface serve as powerful tools for describing types in TypeScript. Your choice should be guided by the unique demands of your project and the desired level of flexibility and extensibility in your type definitions.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

The keyboard that vanished when the Flutter chat input expanded

You tap the expand button in a chat composer. The input flashes, grows to a few lines, and then the keyboard disappears. The screen is now a large, mostly empty editor, and the thing you were typing…

  • Keyboard disappeared during expand due to widget replacement
  • Sluggish animation caused by subscriptions triggering rebuilds
  • Change siblings, not entire element chain for stability

Google's MCP-only rule for Workspace agents starts 1 February. Here's a script that finds the REST calls you'll have to move

If you've built an agent that reads someone's Gmail or Drive, Google changed the ground under it this week. Its Workspace MCP servers went generally available on 24 November, together with a new…

  • Google enforces MCP-only rule for Workspace agents starting February 1, 2027
  • Script provided to find and flag direct Google Workspace REST usage
  • Scanner identifies product names, patterns, and OAuth scopes in code

Free ASO tools and free trials (2026)

Disclosure: I make Asonix, one of the 14. It took me a day of reading pricing pages, help centers and terms (November 28, 2026) to answer it for 14 App Store keyword tools. Five things stood out. 1.

  • Only three ASO tools offer completely free plans without expiration or card requirement.
  • Free plans typically lack crucial data like keyword popularity and difficulty.
  • Five tools provide 7-day trials requiring payment info, with trial lengths from 10 to 30 days.

FrankenCrew: I stitched a Go kernel watchdog, a Kiro Crew, and a WhatsApp poll into one server monster

I wrote this post as part of the Kiroween 2026 hackathon, where FrankenCrew is my entry in the Frankenstein category. Small Linux servers die in a predictable way.

  • FrankenCrew integrates Go kernel watchdog, Kiro Crew, and WhatsApp poll into one server
  • Reflexes component monitors memory metrics and triggers actions within 25% memory usage
  • Human-in-the-loop requires Ed25519 cryptographic vote via WhatsApp poll for irreversible actions

More from Saturday, 28 November 2026 →