npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

farm-plugin-isinterface

v0.2.0

Published

Runtime interface guards for FarmFE — generates isInterface<T>(obj) type guards from TypeScript interfaces at compile time

Readme

farm-plugin-isinterface

Runtime interface type guards for FarmFE — generates isInterface<T>(obj) guard functions from TypeScript interfaces at compile time.

Why?

TypeScript interfaces are erased at runtime. You can't check if an object conforms to an interface at runtime — until now. This plugin reads your TypeScript interfaces and generates efficient runtime type guard functions, then transforms isInterface<T>(obj) calls into direct guard invocations.

Install

pnpm add -D farm-plugin-isinterface

Usage

1. Define interfaces

// user.ts
export interface IUser {
  name: string
  age: number
  email?: string
  roles: string[]
}

export interface IAdmin extends IUser {
  permissions: string[]
}

2. Use isInterface<T>(obj) in your code

// main.ts
import type { IUser, IAdmin } from './user'

const data: unknown = JSON.parse(input)

if (isInterface<IUser>(data)) {
  console.log(data.name)   // TypeScript knows data is IUser
  console.log(data.age)    // ✅ type-safe access
}

if (isInterface<IAdmin>(data)) {
  console.log(data.permissions)  // ✅ type-safe access
}

3. Configure FarmFE

// farm.config.ts
import { defineConfig } from '@farmfe/core'
import isInterface from 'farm-plugin-isinterface'

export default defineConfig({
  plugins: [isInterface()],
})

How It Works

At compile time, the plugin:

  1. Parses all interface declarations in your TypeScript files
  2. Generates runtime guard functions like __isInterface_IUser(obj) { ... }
  3. Transforms isInterface<IUser>(obj)__isInterface_IUser(obj)
  4. Prepends the guard functions to the module

Generated Guard Example

For IUser above, the plugin generates:

function __isInterface_IUser(obj) {
  if (obj === null || typeof obj !== 'object') return false;
  if (!(typeof obj.name === 'string')) return false;
  if (!(typeof obj.age === 'number')) return false;
  if (obj.email !== undefined && !(typeof obj.email === 'string')) return false;
  if (!(Array.isArray(obj.roles) && obj.roles.every(item => typeof item === 'string'))) return false;
  return true;
}

For IAdmin extends IUser:

function __isInterface_IAdmin(obj) {
  if (obj === null || typeof obj !== 'object') return false;
  if (!(Array.isArray(obj.permissions) && obj.permissions.every(item => typeof item === 'string'))) return false;
  if (typeof __isInterface_IUser === 'function' && !__isInterface_IUser(obj)) return false;
  return true;
}

Supported Types

| TypeScript Type | Runtime Check | |---|---| | string, number, boolean, bigint, symbol | typeof obj === 'type' | | null, undefined | obj === null / obj === undefined | | T[] / Array<T> | Array.isArray(obj) && obj.every(...) | | [A, B, C] (tuple) | Array.isArray(obj) && obj.length >= N && ... | | A \| B (union) | (checkA \|\| checkB) | | 'literal' / 123 / true | obj === value | | Record<K, V> | Object.values(obj).every(...) | | Function | typeof obj === 'function' | | any, unknown | true (no check) | | IOther (reference) | __isInterface_IOther(obj) if guard exists | | { ... } (inline object) | Nested property checks |

Options

isInterface({
  // File patterns to include (default: all .ts/.tsx)
  include: [],

  // File patterns to exclude (default: ['node_modules'])
  exclude: ['node_modules'],

  // Auto-generate guards for all exported interfaces (default: true)
  autoGuard: true,

  // Add __isInterface_* exports to the module (default: false)
  exportGuards: false,
})

Cross-Module References

If isInterface<IAdmin>(obj) is called in a file that doesn't define IAdmin, the plugin transforms the call to __isInterface_IAdmin(obj). Make sure the guard function is available at runtime — either:

  • Define IAdmin in the same file, or
  • Import from a file that defines it (the guard is generated there), or
  • Set exportGuards: true and import the guard explicitly

License

MIT