Socket
Book a DemoInstallSign in
Socket

easy-tsnameof

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-tsnameof

Typescript nameOf function. Safe types

3.1.0
latest
Source
npmnpm
Version published
Weekly downloads
8
14.29%
Maintainers
0
Weekly downloads
 
Created
Source

Easy Typescript NameOf

Install

yarn add easy-tsnameof
npm install easy-tsnameof

How to use?

import nameOf from 'easy-tsnameof';

type NameOfTest = {
  test1: {
    test2: {
      test3: string;
    };
  };
};
nameOf<NameOfTest>((o) => o.test1.test2.test3);
// test1.test2.test3

nameOf<NameOfTest>('test1');
// test1

nameOf<NameOfTest, never>().test1.test2.test3.$path;
// test1.test2.test3

Fabrics

import { nameOf } from 'easy-tsnameof';

type NameOfTest = {
  test1: {
    test2: {
      test3: string;
    };
  };
};
const f = nameOf<NameOfTest, never>();
f.test1.test2.test3.$path;
// test1.test2.test3

Working with arrays

import { nameOf } from 'easy-tsnameof';

type NameOfTest = {
  test1: {
    test2: {
      test: string;
    };
    test3: { test4: number }[];
  };
};
const f = nameOf<NameOfTest, never>();
const index = 999;

f.test1.test3[index].test4.$path;
// test1.test3[999].test4

Path access methods

.$path

Access to path string:

nameOf<TestType, never>().a.b.c.d.$path;
// "a.b.c.d"

@m-abboud

.$rawPath

Access to raw path array

Type: (string | number | Symbol)[]

nameOf<TestType, never>().a.b[5].c.d.$rawPath;
// ["a", "b", 5, "c", "d"]

The $rawPath is something that you might want to use with the following methods from Ramda, to add type safety on the path:

Inspired by

Keywords

typescript

FAQs

Package last updated on 10 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.