📝Packages could declare their dependencies’ interface instead of version constraint

up
Interface is second-class for package managers

It is interesting if a package could declare the required interface of a dependency instead of a specific version.

The interface does not need to include the full interface of the library—only functions used. This information might even be deduced automatically from the source code—the required interface is the interface of all functions that are used from a library.

So instead of relying on left-pad@1.0.0, a package would depend on the interface:

module 'left-pad' {
  function leftPad(s: string, n: number): string;
}

Then, the interface can be satisfied by any package that has a leftPad function with the required signature. The dependency is allowed to have extra functions but they won’t influence the compatibility—extra function can be added/changed/removed and package manager can still figure out that the current package is compatible with the dependency.

Cons

  • the package manager needs to derive interfaces
  • version resolution is more complicated—the package manager needs to know about the interface of each package version (it should know about the code—current package managers are mostly agnostic to the internals of the package)

Backlinks

Want to receive my 🖋 posts as I publish them?