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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ktarmyshov/typesafe-utilities

v0.3.7

Published

Type-safe utilities for working in TypeScript. For example, a type-safe property path type, deep partial type, etc.

Readme

NPM Version CI Quality Gate Status Bugs Code Smells Duplicated Lines (%) Socket Badge

typesafe-utilities

Some very specific type-safe utilities that are not available in type-fest (very extensive).

Usage

Property paths

Difference to type-fest:

  • Array property path can be specified like prop1[].prop2 (without index)
  • Does not support tuples
  • Supports only Record<string, unknown>
  • Somewhat better auto-complete for nested arrays of objects
/* eslint-disable @typescript-eslint/no-unused-vars */
import { PropertyPaths } from '../src/paths';

type TestType = {
	prop1: string;
	prop2: number;
	propArr: string[];
	propArr2: {
		propArr3: string[];
	};
	propArr4: {
		propArr5: string[];
	}[];
	prop3: {
		prop4: string;
		prop5: {
			prop6: string[];
		};
	}[];
};

type TestTypePropertyPaths = PropertyPaths<TestType>;

const test1: TestTypePropertyPaths = 'prop1';
const test2: TestTypePropertyPaths = 'prop2';
const test3: TestTypePropertyPaths = 'propArr';
const test4: TestTypePropertyPaths = 'propArr[]';
const test5: TestTypePropertyPaths = 'propArr[0]';
const test6: TestTypePropertyPaths = 'propArr2.propArr3';
const test7: TestTypePropertyPaths = 'propArr2.propArr3[]';
const test8: TestTypePropertyPaths = 'propArr2.propArr3[0]';
const test9: TestTypePropertyPaths = 'propArr4';
const test10: TestTypePropertyPaths = 'propArr4[]';
const test11: TestTypePropertyPaths = 'propArr4[0]';
const test12: TestTypePropertyPaths = 'propArr4[].propArr5';
const test13: TestTypePropertyPaths = 'propArr4[].propArr5[]';
const test14: TestTypePropertyPaths = 'propArr4[].propArr5[0]';
const test15: TestTypePropertyPaths = 'propArr4[0].propArr5';
const test16: TestTypePropertyPaths = 'propArr4[0].propArr5[]';
const test17: TestTypePropertyPaths = 'propArr4[0].propArr5[0]';
const test18: TestTypePropertyPaths = 'prop3';
const test19: TestTypePropertyPaths = 'prop3[]';
const test21: TestTypePropertyPaths = 'prop3[].prop4';
const test22: TestTypePropertyPaths = 'prop3[].prop5';
const test23: TestTypePropertyPaths = 'prop3[].prop5.prop6';
const test24: TestTypePropertyPaths = 'prop3[].prop5.prop6[]';
const test25: TestTypePropertyPaths = 'prop3[0]';
const test26: TestTypePropertyPaths = 'prop3[0].prop4';
const test27: TestTypePropertyPaths = 'prop3[0].prop5';
const test28: TestTypePropertyPaths = 'prop3[0].prop5.prop6';
const test29: TestTypePropertyPaths = 'prop3[0].prop5.prop6[]';
const test30: TestTypePropertyPaths = 'prop3[0].prop5.prop6[0]';

// @ts-expect-error: Invalid property path
const test_e1: TestTypePropertyPaths = ''; // should be error
// @ts-expect-error: Invalid property path
const test_e2: TestTypePropertyPaths = 'prop1.prop2'; // should be error
// @ts-expect-error: Invalid property path
const test_e3: TestTypePropertyPaths = 'prop1[]'; // should be error
// @ts-expect-error: Invalid property path
const test_e4: TestTypePropertyPaths = 'prop1[0]'; // should be error
// @ts-expect-error: Invalid property path
const test_e5: TestTypePropertyPaths = 'propArr.'; // should be error

DeepPartial

/* eslint-disable @typescript-eslint/no-unused-vars */
import { type DeepPartial } from '../src/partial';

type TestType = {
	prop1: string;
	prop2: number;
	propArr: string[];
	propArr2: {
		propArr3: string[];
	};
	propArr4: {
		propArr5: string[];
	}[];
	prop3: {
		prop4: string;
		prop5: {
			prop6: string[];
		};
	}[];
};

type TestTypeDeepPartial = DeepPartial<TestType>;
const test1: TestTypeDeepPartial = {
	prop1: 'test',
	prop2: 123
};
const test2: TestTypeDeepPartial = {
	propArr: ['test1', 'test2'],
	propArr2: {}
};
const test3: TestTypeDeepPartial = {
	propArr2: {
		propArr3: ['test1', 'test2']
	}
};
const test4: TestTypeDeepPartial = {
	propArr4: [{}]
};
const test5: TestTypeDeepPartial = {
	propArr4: [
		{
			propArr5: ['test1', 'test2']
		}
	]
};
const test6: TestTypeDeepPartial = {
	prop3: [{}]
};
const test7: TestTypeDeepPartial = {
	prop3: [
		{
			prop4: 'test',
			prop5: {}
		}
	]
};
const test8: TestTypeDeepPartial = {
	prop3: [
		{
			prop4: 'test',
			prop5: {
				prop6: ['test1', 'test2']
			}
		}
	]
};
const test9: TestTypeDeepPartial = {
	prop3: [
		{
			prop4: 'test',
			prop5: {
				prop6: ['test1', 'test2']
			}
		},
		{}
	]
};

Filter & DeepFilter

/* eslint-disable @typescript-eslint/no-unused-vars */
import {
	DeepFilter,
	type FilterInclude,
	type FilterIncludeKeys,
	type NonNeverKeys,
	type OmitNever
} from '../src/filter';
import { type Equal, type Expect } from './helpers';

type TestType = {
	a: string;
	b: number;
	c: boolean;
};

type asserts_FilterKeys = [
	Expect<Equal<FilterIncludeKeys<TestType, string | number>, 'a' | 'b'>>,
	Expect<Equal<FilterIncludeKeys<TestType, string>, 'a'>>,
	Expect<Equal<FilterIncludeKeys<TestType, number>, 'b'>>,
	Expect<Equal<FilterIncludeKeys<TestType, boolean>, 'c'>>,
	Expect<Equal<FilterIncludeKeys<TestType, unknown>, 'a' | 'b' | 'c'>>
];

type asserts_Filter = [
	Expect<Equal<FilterInclude<TestType, string | number>, { a: string; b: number }>>,
	Expect<Equal<FilterInclude<TestType, string>, { a: string }>>,
	Expect<Equal<FilterInclude<TestType, number>, { b: number }>>,
	Expect<Equal<FilterInclude<TestType, boolean>, { c: boolean }>>,
	Expect<Equal<FilterInclude<TestType, unknown>, TestType>>
];

type TestTypeNever = {
	a: string;
	b: number;
	c: boolean;
	d: never;
};

type asserts_NeverKeys = [
	Expect<Equal<NonNeverKeys<TestType>, 'a' | 'b' | 'c'>>,
	Expect<Equal<NonNeverKeys<TestTypeNever>, 'a' | 'b' | 'c'>>
];

type asserts_OmitNever = [
	Expect<Equal<OmitNever<TestType>, TestType>>,
	Expect<Equal<OmitNever<TestTypeNever>, { a: string; b: number; c: boolean }>>
];

type TestTypeDeep = {
	a: string;
	b: number;
	c: boolean;
	d: {
		e: string;
		f: number;
		g: boolean;
	};
	h: {
		i: string;
		j: number;
		k: boolean;
	}[];
};

type asserts_DeepFilter = [
	Expect<
		Equal<DeepFilter<TestTypeDeep, string>, { a: string; d: { e: string }; h: { i: string }[] }>
	>,
	Expect<
		Equal<DeepFilter<TestTypeDeep, number>, { b: number; d: { f: number }; h: { j: number }[] }>
	>,
	Expect<
		Equal<DeepFilter<TestTypeDeep, boolean>, { c: boolean; d: { g: boolean }; h: { k: boolean }[] }>
	>,
	Expect<
		Equal<
			DeepFilter<TestTypeDeep, string | number>,
			{ a: string; b: number; d: { e: string; f: number }; h: { i: string; j: number }[] }
		>
	>,
	Expect<Equal<DeepFilter<TestTypeDeep, unknown>, TestTypeDeep>>
];