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

class-properties

v1.1.0

Published

Decorate class properties in TypeScript so they can be known at runtime

Readme

class-properties

Decorate class properties in TypeScript to allow the class's property names to be known at runtime.

This allows objects to be checked for missing or excess properties compared to a class.

For more comprehensive decorator-based object validation, consider class-validator.

Installation

yarn add class-properties

Usage

Decorate class properties with the @Property decorator:

import { Property } from 'class-properties';

class Test {
  @Property()
  field1!: string;

  @Property()
  field2!: string;
}

Then retrieve the decorated property names as a string array at runtime:

import { getClassProperties } from 'class-properties';

const properties = getClassProperties(Test);
// properties = ['field1', 'field2']

You can also compare objects with the class's known properties to determine if it has extra or missing properties:

import { compareProperties } from 'class-properties';

const testObject = {
  field2: 'field2',
  field3: 'field3',
};

const result = compareProperties(testObject, Test);
// result.missing = ['field1']
// result.extra = ['field3']

Motivation

This may be useful for two reasons:

  1. TypeScript's structural typing means that object literals may include excess properties and remain compatible with a type.
  2. Since we are compiling to JavaScript there is not a runtime guarantee that the properties of an object match those which were expected.

We may need to confirm our assumptions of the properties that should be present if, for example, handling a data transfer object or passing a model to an ORM.

This is typically handled through a validation library, but in some scenarios a simpler approach may be sufficient.

Implementation

Property names are stored in the reflect-metadata store for the class's prototype under the key __class-properties.

FAQs

Is it possible to determine interface properties at runtime?

No. TypeScript interfaces do not exist in compiled JavaScript, and there is no way to decorate them.

Are property types or modifiers accessible?

No. Only property names are stored. TypeScript types do not exist in compiled JavaScript, so it is not possible to read them via decorator.