Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 820 Bytes

being_loosly_coupled.md

File metadata and controls

54 lines (39 loc) · 820 Bytes

type vs. interface

Use type when you might need a union or intersection. Use an interface when you want extends or implements. There is no strict rule, however, use the one that works for you.
For a more detailed explanation refer to this answer about the differences between type and interface in TypeScript.

Bad:

interface EmailConfig {
  // ...
}

interface DbConfig {
  // ...
}

interface Config {
  // ...
}

//...

type Shape = {
  // ...
};

Good:

type EmailConfig = {
  // ...
};

type DbConfig = {
  // ...
};

type Config = EmailConfig | DbConfig;

// ...

interface Shape {
  // ...
}

class Circle implements Shape {
  // ...
}

class Square implements Shape {
  // ...
}