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

partial-class

v0.0.9

Published

Partial Class Experimental Library

Readme

Partial Class Experimental Library

TypeScript does not support partial classes in the same way that .NET does. In .NET, partial classes allow you to split the definition of a class across multiple files, which can be useful for organizing large classes or separating auto-generated code from manually written code.

However, you can achieve similar functionality in TypeScript using other techniques, such as class inheritance, mixins, or module augmentation.

None of these are practicle, as it adds complexity on chaining partial classes, and maintain the code. However, combining these techniques can greatly helps.

Installation

npm install partial-class --save

Example

partials/partial-1.ts

import { Partial } from 'partial-class';

@Partial('MyClass')
export class MyClassPartial1 {
	/// ...
}

// or

@Partial
export class MyClass {
	/// ...
}

partials/partial-2.ts

import { Partial } from 'partial-class';

@Partial('MyClass')
export class MyClassPartial2 {
	/// ...
}

// or

@Partial
export class MyClass {
	/// ...
}

and more if you'd like.

MyClass.ts

import { Final } from 'partial-class';
export * from './partials/partial-1';
export * from './partials/partial-2';

@Final
export class MyClass {
	/// ...
}

Limitations

All instance properties must be implemented in MyClass. Due to the nature of Javascript, it is impossible to create instance properties in partial classes. This is ok for static properties.

How to deal with this limitation:

partials/partial-1.ts

@Partial('MyClass')
export class MyClassPartial1 {
	// public myVar!: string; // Do not do this
	declare public myVar: string; // Do this only if you need it in MyClassPartial1 class
	/// ...
}

MyClass.ts

@Final
export class MyClass {
	public myVar: string = ''; // This is where it needs to be
	/// ...
}

Need to Know

If you implement twice the same property (static), accessoror or method into two different partial class, the latest overrides the previous version.

Make TS and VSCode happy

The easiest way is to augment your class with the public properties, accessors and methods. There is a script to create those augmentation file automatically. The sample provide uses it, but you can also call it manually.

cd ./src/sample
ts-node ../lib/scripts/dts-build.ts -P . ./final.ts ./tsconfig.json
# will output ./final.d.ts

Installing the automatic augmentation file generation

In VSCode,

Install the 'Trigger Task on Save' extenstion.

.vscode/settings.json

{
	...
	"triggerTaskOnSave.tasks": {
		"create_dts": [
			"!**/*.d.ts",
			"!**/*.d.tsx",
			"**/*.ts",
			"**/*.tsx",
		],
	},
	...
}

.vscode/tasks.json

{
	...
	{
		"label": "create_dts",
		"type": "shell",
		"isBackground": true,
		"command": "ts-node",
		"args": [
			"-P",
			"${workspaceFolder}/src/sample",
			"${workspaceFolder}/node_modules/partial-class/bin/scripts/dts-build.js",
			"${file}",
			"${workspaceFolder}/src/sample/tsconfig.json"
		],
		"problemMatcher": [],
		"group": {
			"kind": "build",
			"isDefault": true
		},
		"presentation": {
			"echo": false,
			"reveal": "never",
			"focus": false,
			"panel": "dedicated",
		},
	},
	...
}

License

MIT License