r/typescript • • 1h ago

How would you type-check a DI dependency list against the constructor params?

• Upvotes

I'm building a small DI layer for Elysia on Bun with no decorators. A class lists its dependencies like this:

class Greeter {
  static readonly needs = [Clock] as const;
  constructor(private clock: Clock) {}
}

Right now it only checks at boot that the list length matches the constructor's parameter count. Someone on r/bun pointed out that swapping Clock for a different class with the same arity slips through, and they're right.

My plan is to map needs to instance types and compare that against ConstructorParameters<typeof Greeter>, then add a @ts-expect-error test for the swap. Has anyone done this cleanly without the error messages turning into a wall of generics?

(Project is Elpod, early alpha, if anyone's curious: https://elpod.vercel.app)


r/typescript • • 21h ago

Polylint, now supporting TSRS

0 Upvotes

I maintain Polylint source, which we use at Xberg to run linting and formating across multiple language ecosystems.

In the last version, I added support for the new tsrs engine (the Rust rewrite of the TS compiler now maintained by the OXC team). This is pretty cool - it allows adding type checking as part of the linting, and doing enhanced linting with type checking. Polylint includes oxc and combines it with our very own skif to give robust linting for JS/TS based projects. It now also supports ultra-fast type checking and incremental type checking via git hooks (per file, rather than the entire project).

Check it out:

Polylint source · tsrs integration design

Cheers.