3.0.6 • Published 3 years ago
easy-tsnameof v3.0.6
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"
.$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
3.0.4
3 years ago
3.0.3
3 years ago
3.0.2
3 years ago
3.0.1
3 years ago
3.0.6
3 years ago
3.0.5
3 years ago
3.0.0
3 years ago
2.0.2
3 years ago
2.1.0
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.1.2
4 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago