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

@esnark/mikro-typerider

v0.1.0

Published

Override property types on auto-generated MikroORM v7 entities — both TypeScript types and runtime metadata in one step.

Readme

@esnark/mikro-typerider

Override property types on auto-generated MikroORM v7 entities — both TypeScript types and runtime metadata in one step.

Problem

Code generators produce entity classes with generic types like string or unknown for columns that actually store structured data (e.g., PHP-serialized JSON). You want to use a custom Type<T> for these columns, but:

  • Redefining properties with declare causes TypeScript type mismatches
  • Subclassing creates a second entity mapped to the same table, which MikroORM rejects

Solution

OverrideType creates an intermediate class that swaps the customType in MikroORM's metadata and adjusts the TypeScript type — without table conflicts.

import { Entity } from '@mikro-orm/core';
import { OverrideType } from '@esnark/mikro-typerider';
import { ShopOrder } from '@imwebme/mikro-models/doznut_shop';
import { PhpSerializedType } from './types/php-serialized-type.js';

@Entity({ tableName: 'shop_order', schema: 'doznut_shop' })
class AppShopOrder extends OverrideType(ShopOrder, {
  refundData: new PhpSerializedType<Record<string, unknown>>(),
  payBankInfo: new PhpSerializedType<BankInfo>(),
}) {}

const order = await em.findOne(AppShopOrder, { idx: 1 });
order.refundData;  // Record<string, unknown>  (was unknown)
order.payBankInfo; // BankInfo | null           (was string | null)
order.code;        // string                    (unchanged)

Install

npm install @esnark/mikro-typerider

Requires @mikro-orm/core v7+ as a peer dependency.

API

OverrideType(parentClass, overrides)

Returns a new class extending parentClass with the specified property types replaced.

  • parentClass — A MikroORM entity class (decorated with @Entity)
  • overrides{ propertyName: new CustomType() } map of properties to override

The override map values must be instances of MikroORM's Type<JSType, DBType>. The JSType generic parameter becomes the new TypeScript type for that property.

Nullable preservation: If the original property is nullable (T | null), the overridden type stays nullable (NewType | null).

Type utilities

import type { InferJSType, ApplyOverrides, OverrideMap } from '@esnark/mikro-typerider';
  • InferJSType<T> — Extracts the JS type from Type<JSType, DBType>
  • ApplyOverrides<Entity, Overrides> — Computes the resulting entity type
  • OverrideMapRecord<string, Type<any, any>>

How it works

  1. Creates an abstract intermediate class extending the parent
  2. Deep-copies the parent's EntityMetadata.properties from MikroORM's global MetadataStorage
  3. Replaces customType and type on overridden properties
  4. Marks the intermediate class as abstract so MikroORM doesn't map it to a table
  5. When @Entity() is applied to your final class, MikroORM's discovery walks the prototype chain and inherits the modified properties

License

MIT