Recommend: Don't use this package
See original GitHub issueI now recommend not using this package or any other compiler transforms. It’s neat, but it creates code that is not portable and makes it hard to switch to new build systems. The current solutions for injecting compiler transforms are hacky and I can’t imagine the TS compiler ever supporting this out of the box.
I personally now just use the following function. It’s simple and it works for most cases… of course it’s not as featureful, but it gets you 90% of the way there.
export function nameof<TObject>(obj: TObject, key: keyof TObject): string;
export function nameof<TObject>(key: keyof TObject): string;
export function nameof(key1: any, key2?: any): any {
return key2 ?? key1;
}
Example Use
import { nameof } from "./some-relative-import";
interface SomeInterface {
someProperty: number;
}
// with types
console.log(nameof<SomeInterface>("someProperty")); // "someProperty"
// with values
const myVar: SomeInterface = { someProperty: 5 };
console.log(nameof(myVar, "someProperty")); // "someProperty"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:26
- Comments:10 (1 by maintainers)
Top Results From Across the Web
apt - How to not install recommended and suggested packages?
Use apt-mark hold package-that-apt-should-leave-alone . hold hold is used to mark a package as held back, which will prevent the package from being ......
Read more >Best practices for writing Dockerfiles - Docker Documentation
This document covers recommended best practices and methods for building ... Use this syntax to build an image using a Dockerfile from stdin...
Read more >Package Delivery Boxes to Deter Porch Pirates
At-Home Review: Package Delivery Boxes to Deter Porch Pirates. These dedicated drop boxes could prevent package theft—if delivery drivers were ...
Read more >When not to use package-lock.json - DEV Community
I am not advocating against using package-lock.json for programs designed to be consumed by the end consumer. I do suggest not to use...
Read more >Publishing and installing a package with GitHub Actions
If you want your workflow to access a GitHub Packages registry that does not support granular permissions, then we recommend using the GITHUB_TOKEN...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I published package ts-keyof. Maybe it will be useful for someone. Thanks for ts-nameof! I used it about 3 years, but now I need use esbuild and swc.
Thank you for your candor. It would be awesome if you also write a note to this answer https://stackoverflow.com/a/33556815/1177597 when you have spare time.