GithubHelp home page GithubHelp logo

ts-nameof's Introduction

ts-nameof

Build Status

nameof in TypeScript.

Monorepo for ts-nameof projects:

Recommend: Don't use this package

See here.

Setup

ts-nameof is a compile time transform so it requires some setup. For setup instructions, see the packages above for the compiler you use.

nameof transform

nameof(...)

nameof(console);
nameof(console.log);
nameof(console["warn"]);

Transforms to:

"console";
"log";
"warn";

nameof<T>()

nameof<MyInterface>();
nameof<Array<MyInterface>>();
nameof<MyNamespace.MyInnerInterface>();

Transforms to:

"MyInterface";
"Array";
"MyInnerInterface";

This is useful when working in the type domain.

nameof<T>(o => ...)

nameof<MyInterface>(o => o.prop);

Transforms to:

"prop";

nameof.full transform

nameof.full(...)

nameof.full(console.log);
nameof.full(window.alert.length, 1);
nameof.full(window.alert.length, 2);
nameof.full(window.alert.length, -1);
nameof.full(window.alert.length, -2);
nameof.full(window.alert.length, -3);

Transforms to:

"console.log";
"alert.length";
"length";
"length";
"alert.length";
"window.alert.length";

nameof.full<T>()

nameof.full<MyNamespace.MyInnerInterface>();
nameof.full<MyNamespace.MyInnerInterface>(1);
nameof.full<Array<MyInterface>>();

Transforms to:

"MyNamespace.MyInnerInterface";
"MyInnerInterface";
"Array";

nameof.full<T>(o => ...)

nameof.full<MyInterface>(o => o.prop.prop2);
nameof.full<MyInterface>(o => o.prop.prop2.prop3, 1);

Transforms to:

"prop.prop2";
"prop2.prop3";

nameof.interpolate(value)

Writing the following:

nameof.full(myObj.prop[i]);

...does not interpolate the node in the computed property.

"myObj.prop[i]";

If you want to interpolate the value then you can specify that explicitly with a nameof.interpolate function.

nameof.full(myObj.prop[nameof.interpolate(i)]);

Transforms to:

`myObj.prop[${i}]`;

nameof.toArray transform

Contributed by: @cecilyth

nameof.toArray(...)

nameof.toArray(myObject, otherObject);
nameof.toArray(obj.firstProp, obj.secondProp, otherObject, nameof.full(obj.other));

Transforms to:

["myObject", "otherObject"];
["firstProp", "secondProp", "otherObject", "obj.other"];

nameof.toArray<T>(o => [...])

nameof.toArray<MyType>(o => [o.firstProp, o.otherProp.secondProp, o.other]);
nameof.toArray<MyType>(o => [o.prop, nameof.full(o.myProp.otherProp, 1)]);

Transforms to:

["firstProp", "secondProp", "other"];
["prop", "myProp.otherProp"];

nameof.split transform

Contributed by: @cecilyth

nameof.split(...)

nameof.split(myObj.prop.prop2);
nameof.split(myObj.prop.prop2, 1);
nameof.split(myObj.prop.prop2, -1);
nameof.split(myObj.prop.prop2).join("/");

Transforms to:

["myObj", "prop", "prop2"];
["prop", "prop2"];
["prop2"];
["myObj", "prop", "prop2"].join("/"); // "myObj/prop/prop2"

nameof.split<T>(o => ...)

nameof.split<MyInterface>(o => o.prop.prop2.prop3);
nameof.split<MyInterface>(o => o.prop.prop2.prop3, 1);
nameof.split<MyInterface>(o => o.prop.prop2.prop3, -1);
nameof.split<IState>(s => s.a.b.c).join("/");

Transforms to:

["prop", "prop2", "prop3"];
["prop2", "prop3"];
["prop3"];
["a", "b", "c"].join("/"); // "a/b/c"

Other

ts-nameof's People

Contributors

cecilyth avatar dsherret avatar g-rath avatar kukks avatar parloti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ts-nameof's Issues

Support `typeof import` as `nameof` generic

Suppose module './modules/ModuleName' exposes a non-default export named Foo.

Use case: I would like to use nameof<typeof import('./modules/ModuleName')>(x => x.Foo) to obtain the string 'Foo' without the overhead of actually importing the component, but with full compile-time path checking and type safety.

Currently it breaks as unsupported node type.

Can we enable support for this recent TS feature? It would make a lot of JS much more lightweight.

Issues with source-map generation

In the Ionic project. use webpack ts-nameof-loader.

When the rule is:

      {
        test: /\.ts$/i,
        exclude: /node_modules/,
        loader: "ts-nameof-loader"
      }

ts-nameof work normally, but sourcemap abnormal.

When the rule is:

      {
        test: /\.ts$/i,
        enforce: "pre",
        exclude: /node_modules/,
        loader: "ts-nameof-loader"
      }

ts-nameof not working, but sourcemap normal.

Using with a create-react-app (v2) project

Any pointers on how it might be possible to use ts-nameof with a react project using create-react-app. That now uses babel for the typescript compilation so I'm unsure if it provides the configuration points necessary to set this up?

Add pipe-stream support

Right now I can only target files.
Is it possible to add support for something like this:

gulp.src('src/**/*.ts')
.pipe(ts(...))
.pipe(ts-nameof()) <-------------------------------
.pipe(gulp.dest('built/dist'));

import into Angular2

Hey, I was trying to add your library to my angular2 Project, and when i import, by adding /// reference to my app.module.ts I recive this error: Cannot find namespace 'NodeJS', any idea how to use it with angular2?

Support generation of path array

For some reasons, I want to get splitted into the array path instead of string. I mean 'state.field' becomes ['state', 'field'].
Is it possible to do? Something like nameof.split<IState>(o => o.state.field);

Support custom path signature

I appreciate that the current output matches the code expectation:

nameof.full<IState>(state => state.a.b.c); becomes a.b.c. But I think sometimes that the path signature might need to be different.

For this it would be good to do:

nameof.full<IState>(state => state.a.b.c, "/"); (or similar) which would compile to a/b/c

I suppose it would be possible to apply a simple string replace, but just curious if it would be something for the core?

Cannot find name 'nameof'. on Angular2

Hey, i want to implement your library to my angular2 project, so first I download it via npm, then i add

/// <reference path="../../node_modules/ts-nameof/ts-nameof.d.ts" />

to my app.module.ts file and in constructor of my base app.component im using nameof function, Webstorm doesn't find this error, but when i run "ng serve" this apears:

(14,17): Cannot find name 'nameof'. Did you mean 'name'?

Parser will break if file contains regex with string char

I just thought of this scenario (untested, but I'm pretty sure it won't work):

const t = /`/g; 

nameof(T); // won't work

Basically, the parser needs to be improved to detect when it's within a regular expression literal.

Edit 2018-05-01: This is a very rare scenario to encounter, but I should fix this ASAP.

How to use with @babel/preset-typescript

I am not sure if this is the same issue as #36, but it would be really nice to have a way to use this with @babel/preset-typescript. Since there is no transformer option, is there a more low-level way we could do this?

Installation instruction for React

I'm trying to use this in a React project.
Because I'm fairly new to TypeScript, I can't figure out how to "import" this in my project after installing with npm. Only the Api seems to be exported.
Thanks in advance.

Use with Jest

I followed the instructions for integrating with Jest. It works.

However I got a warning:

ts-jest[main] (WARN) Replace any occurrences of "ts-jest/dist/preprocessor.js" or "/node_modules/ts-jest/preprocessor.js" in the 'transform' section of your Jest config with just "ts-jest".

So I did that, but it doesn't work:

transform: {
  "^.+\\.ts$": "ts-jest"
}

I also tried something I found at ts-jest, but it doesn't work:

globals: {
  "ts-jest": {
    "compiler": "ttypescript"
  }
}

The warning implies it's possible - with some tweaking we could avoid the preprocessor and increase speed.

Has anyone got this to work?

cc @dsherret, @Kukks

Babel support

As title.

This will solve #37 and I believe #36.

Edit: To do this effectively I will have to parse a shared representation from the ASTs of babel and typescript, then share the logic for determining the final string node (as a way of reducing code duplication and maintenance overhead).

[Question] Use nameof inside decorator

I'm using the inversify IOC container.

This is used in controllers' action methods:

@httpGet("/:id")
public async getUser(@requestParam("id") id: number): Promise<User> {     // <----- "id"
  // ...
}

None of these things are available in that context: this, arguments, id.

Is there some trick to avoid that "id" magic string in the argument list?


A workaround:

const names = {
  getUser: {
    id: "id"
  }
};

And then: nameof(names.getUser.id). But that's not ideal.

Support comments in nameof

No reason for someone to do this, but need to handle this:

nameof(/*some text*/variable);

Or:

nameof( // some comment
    variable
);

Both to:

"variable";

Using ts-nameof with grunt

Hi,

I am trying to set this library up with grunt, but there doesn't seem to be an easy way to do this. I cant use TSC way either as it is relying on another dependency:

https://github.com/dsherret/ts-nameof/blob/master/packages/ts-nameof/setup/tsc.md

Custom set up requires me to write my own transformer, which is not the direction i want to go. So is it possible to use this package with grunt without an overly complicated set up?

https://github.com/dsherret/ts-nameof/blob/master/packages/ts-nameof/setup/custom.md

Thanks
Juju

Fully qualified nameof

Instead of this:

`${nameof(opts)}.${nameof(opts.node)}`

It would be nicer to write something like:

`${nameof.full(opts.node)}`

Send function to nameof.full

It's possible to send function to the nameof. How about the same functionality for nameof.full?
Something like

declare namespace nameof {
    function full<T>(func?: (obj: T) => void, periodIndex?: number): string;
}

Question: how should this be referenced?

I've installed the packages, and the documentation says I now need to add this:

/// <reference path="node_modules/ts-nameof/ts-nameof.d.ts" />

But I don't understand where? In every ts file where I use nameof? That would be messy. I assume there is some magic way to include this once for the entire project, but I'm not sure how.

So I did some digging and discovered another way. By adding to my root tsconfig.json:

"files": ["node_modules/ts-nameof/ts-nameof.d.ts"]

But that also doesn't work ([ts] Cannot find name 'nameof').

What is the correct way to do this?

Single quote within ticks breaks nameof

The following code fails on the final nameof:

import CodeBlockWriter from "code-block-writer";
import {expect} from "chai";
import {FunctionDefinition, InterfaceMethodDefinition, ClassMethodDefinition} from "./../../definitions";
import {FunctionBodyWriter} from "./../../writers";
import {WriteFlags} from "./../../WriteFlags";
import * as mocks from "./mocks";

describe(nameof(FunctionBodyWriter), () => {
    function createObjects() {
        const writer = new CodeBlockWriter();
        const defWriter = new FunctionBodyWriter(writer);
        return {writer, defWriter};
    }

    describe(nameof<FunctionBodyWriter>(w => w.write), () => {

        it(`should not write out the function body if ${nameof(WriteFlags.HideFunctionBodies)} is set`, () => {
            const def = new FunctionDefinition();
            const {writer, defWriter} = createObjects();
            defWriter.write(def, WriteFlags.HideFunctionBodies);
            expect(writer.toString()).to.equal(";");
        });

        it(`should not write out the function body if it's an ${nameof(InterfaceMethodDefinition)}`, () => {
            const def = new InterfaceMethodDefinition();
            const {writer, defWriter} = createObjects();
            defWriter.write(def, WriteFlags.None);
            expect(writer.toString()).to.equal(";");
        });
    });
});

Omit non-null assertion operator in path

Next code nameof.full<IState>(state => IState.optionalField!.anotherField) generates the string 'optionalField!.anotherField'.
Probably, the ! operator should be omitted

Move to using the transformation api

As title.

Edit (5 May 2017): This change will be made to ts-nameof once the TypeScript compiler easily supports injecting transformations. See this issue and upvote it if you support the idea.

Confused about the setup

Hi,

I was so happy to find out that this package existed, but when I tried to use it, I was so confused.

Am I missing something? I'm asking because the setup seems too complicated. Can it not be just a normal import nameof from 'ts-nameof' and then use it?

Add periodIndex parameter to nameof.full

Idea is from #11.

nameof.full(obj: any, periodIndex: number = 0);

Examples:

nameof.full(this.x.y.z) // "this.x.y.z"
nameof.full(this.x.y.z, 0) // "this.x.y.z"
nameof.full(this.x.y.z, 1) // "x.y.z"
nameof.full(this.x.y.z, 2) // "y.z"
nameof.full(this.x.y.z, 3) // "z"
nameof.full(this.x.y.z, 4) // build error
nameof.full(this.x.y.z, -1) // "z"
nameof.full(this.x.y.z, -2) // "y.z"
nameof.full(this.x.y.z, -3) // "x.y.z"
nameof.full(this.x.y.z, -4) // "this.x.y.z"
nameof.full(this.x.y.z, -5) // build error

The second parameter should only directly accept number literals. In the future when this library uses the transformation api it could changed support constants.

nameof with arrays

Hello!

I'm using ts-nameof of in conjuction with lodash _.set function to strongly type object paths in reactJS.
I don't know if this an error or a misuse of the package by me:

When I try to make something like this:

     var elem = {
            value: "Val",
            items: [
                {
                    prop1: 1,
                    prop2: "pepe"
                }]
        }

        console.log(nameof(elem.items[0].prop1));

I get this error:

Module build failed: Error: Invalid character in nameof argument: [ -- if this should be a valid character then please log an issue. If you wish, you can manually edit config.js in this package to allow the character.
    at throwInvalidCharacterInArg (D:\Documenta2\TLaw.Docu2\src\TLaw.Docu2.PublicWeb\node_modules\ts-nameof\dist\handleNameOf.js:155:11)
    at tryGetArgs (D:\Documenta2\TLaw.Docu2\src\TLaw.Docu2.PublicWeb\node_modules\ts-nameof\dist\handleNameOf.js:118:24)
    at Object.handleNameOf (D:\Documenta2\TLaw.Docu2\src\TLaw.Docu2.PublicWeb\node_modules\ts-nameof\dist\handleNameOf.js:18:21)
    at NameOfFinder.indexOfAll (D:\Documenta2\TLaw.Docu2\src\TLaw.Docu2.PublicWeb\node_modules\ts-nameof\dist\NameOfFinder.js:20:53)
    at Function.replaceInText (D:\Documenta2\TLaw.Docu2\src\TLaw.Docu2.PublicWeb\node_modules\ts-nameof\dist\replaceInText.js:8:26)
    at Object.module.exports (D:\Documenta2\TLaw.Docu2\src\TLaw.Docu2.PublicWeb\node_modules\ts-nameof-loader\main.js:3:26)

I'm trying to get "elem.items[0].prop1".

Any idea? THANKS

Support an array of names

Could we have support for an array of values that returns an array.

e.g.

myProperties: string[] = nameof<Company>(o => o.Name, o => o.Address1, o => o.Address2);

transpiles to:

myProperties = ["Name", "Address1", "Address2"];

Maybe even call it namesOf?

How to use with Webstorm (plain typescript import would also be acceptable)

I'm using:
webstorm: 2018.3.1

and here is my package.json:

{
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
  },
  "author": "OSW Technologies Pvt Ltd",
  "license": "All rights reserved",
  "dependencies": {
    "chai": "^3.5.0",
    "chokidar": "^2.0.3",
    "filenamify": "^2.1.0",
    "jquery": "*",
    "lodash": "^4.17.10",
    "shelljs": "^0.8.3",
    "ts-nameof": "^2.0.0",
    "winston": "^3.1.0"
  },
  "devDependencies": {
    "@types/chai": "^3.5.2",
    "@types/chokidar": "^1.7.5",
    "@types/jquery": "^2.0.51",
    "@types/lodash": "^4.14.118",
    "@types/moment": "^2.13.0",
    "@types/node": "^10.12.11",
    "@types/shelljs": "^0.8.0",
    "ndb": "^1.0.38",
    "typescript": "^2.9.2"
  },
}

Issue

I would like to either use ts-nameof in a way which is compatible with webstorm. I've a tsconfig.json and not sure how to get ttypescript or webpack to work with webstorm. Can you please guide me?

I'd like it if it was just possible to import it and use it. Is this possible?

[Feature Request] Changelog

As the typical changelog.md or changelog.txt in the project's root. So we know what's changed before upgrading.

use ts-nameof with Angular CLI

I am not sure if I looked at the right places I couldn't find any useful info on how to use it in an Angular CLI Project..

Support properties of types

Do this:

nameof<MyClass>(t => t.someProperty);

Goes to:

"someProperty";

Don't support nameof.full for this (unless someone can think of a good reason to).

Allow $ in nameof

VueJs utilizes a $ on some reserved view model keywords and using nameof with them causes the following error:

Error: Invalid character in nameof argument: $ -- if this should be a valid character then please log an issue. If you wish, you can manually edit config.js in this package to allow the character.

I'm thinking it should be globally allowed from the plugin itself

React Native : Uncaught ReferenceError: nameof is not defined error at runtime

I'm trying to use your utility in a ReactXP project.
I've followed the instruction to reference the path.
It compiles ok, but I have the following error at runtime on web:

Uncaught ReferenceError: nameof is not defined
    at Object.EditExerciseCategoryPropertiesPanel._this._onChangeActivityTag [as onActivityTagChange] (EditExerciseCategoryPropertiesPanel.tsx:120)
    at Object.CategoryPicker._this._onActivityTagValueChange [as onValueChange] (CategoryPicker.tsx:84)
    at Picker._this._onValueChange (Picker.js:32)
    at HTMLUnknownElement.callCallback (react-dom.development.js:1299)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:1338)
    at Object.invokeGuardedCallback (react-dom.development.js:1195)
    at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:1209)
    at executeDispatch (react-dom.development.js:1432)
    at Object.executeDispatchesInOrder (react-dom.development.js:1454)
    at executeDispatchesAndRelease (react-dom.development.js:1969)
EditExerciseCategoryPropertiesPanel._this._onChangeActivityTag @ EditExerciseCategoryPropertiesPanel.tsx:120
CategoryPicker._this._onActivityTagValueChange @ CategoryPicker.tsx:84
Picker._this._onValueChange @ Picker.js:32
callCallback @ react-dom.development.js:1299
invokeGuardedCallbackDev @ react-dom.development.js:1338
invokeGuardedCallback @ react-dom.development.js:1195
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:1209
executeDispatch @ react-dom.development.js:1432
executeDispatchesInOrder @ react-dom.development.js:1454
executeDispatchesAndRelease @ react-dom.development.js:1969
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:1980
forEachAccumulated @ react-dom.development.js:1946
processEventQueue @ react-dom.development.js:2139
runEventQueueInBatch @ react-dom.development.js:2151
handleTopLevel @ react-dom.development.js:2161
handleTopLevelImpl @ react-dom.development.js:1800
batchedUpdates @ react-dom.development.js:13238
performFiberBatchedUpdates @ react-dom.development.js:1646
stackBatchedUpdates @ react-dom.development.js:1637
batchedUpdates @ react-dom.development.js:1651
batchedUpdatesWithControlledComponents @ react-dom.development.js:1664
dispatchEvent @ react-dom.development.js:1874
react-dom.development.js:1345 Uncaught Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development. See https://fb.me/react-crossorigin-error for more information.
    at Object.invokeGuardedCallbackDev (react-dom.development.js:1345)
    at Object.invokeGuardedCallback (react-dom.development.js:1195)
    at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:1209)
    at executeDispatch (react-dom.development.js:1432)
    at Object.executeDispatchesInOrder (react-dom.development.js:1454)
    at executeDispatchesAndRelease (react-dom.development.js:1969)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:1980)
    at Array.forEach (<anonymous>)
    at forEachAccumulated (react-dom.development.js:1946)
    at Object.processEventQueue (react-dom.development.js:2139)
invokeGuardedCallbackDev @ react-dom.development.js:1345
invokeGuardedCallback @ react-dom.development.js:1195
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:1209
executeDispatch @ react-dom.development.js:1432
executeDispatchesInOrder @ react-dom.development.js:1454
executeDispatchesAndRelease @ react-dom.development.js:1969
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:1980
forEachAccumulated @ react-dom.development.js:1946
processEventQueue @ react-dom.development.js:2139
runEventQueueInBatch @ react-dom.development.js:2151
handleTopLevel @ react-dom.development.js:2161
handleTopLevelImpl @ react-dom.development.js:1800
batchedUpdates @ react-dom.development.js:13238
performFiberBatchedUpdates @ react-dom.development.js:1646
stackBatchedUpdates @ react-dom.development.js:1637
batchedUpdates @ react-dom.development.js:1651
batchedUpdatesWithControlledComponents @ react-dom.development.js:1664
dispatchEvent @ react-dom.development.js:1874

On iPhone:

Can't find variable: nameof
_onChangeActivityTag
EditExerciseCategoryPropertiesPanel.js:73:30

Android:

Can't find variable: nameof
_onChangeActivityTag
    EditExerciseCategoryPropertiesPanel.js:73:30
_onActivityTagValueChange
    CategoryPicker.js:52:48
onValueChange
    Picker.js:38:38
_onChange
    PickerAndroid.android.js:120:33
invokeGuardedCallback
    ReactNativeStack-dev.js:130:19
invokeGuardedCallback
    ReactNativeStack-dev.js:166:43
invokeGuardedCallbackAndCatchFirstError
    ReactNativeStack-dev.js:169:64
executeDispatch
    ReactNativeStack-dev.js:202:128
executeDispatchesInOrder
    ReactNativeStack-dev.js:208:279
executeDispatchesAndRelease
    ReactNativeStack-dev.js:272:58
executeDispatchesAndReleaseTopLevel
    ReactNativeStack-dev.js:276:39
forEachAccumulated
    ReactNativeStack-dev.js:268:65
processEventQueue
    ReactNativeStack-dev.js:340:143
runEventQueueInBatch
    ReactNativeStack-dev.js:637:79
handleTopLevel
    ReactNativeStack-dev.js:642:29
<unknown>
    ReactNativeStack-dev.js:749:51
fiberBatchedUpdates
    ReactNativeStack-dev.js:691:14
performFiberBatchedUpdates
    ReactNativeStack-dev.js:695:31
perform
    ReactNativeStack-dev.js:1382:99
batchedUpdates
    ReactNativeStack-dev.js:2077:139
batchedUpdates$1
    ReactNativeStack-dev.js:1456:61
batchedUpdates
    ReactNativeStack-dev.js:699:31
batchedUpdatesWithControlledComponents
    ReactNativeStack-dev.js:708:30
_receiveRootNodeIDEvent
    ReactNativeStack-dev.js:748:46
receiveEvent
    ReactNativeStack-dev.js:754:56
__callFunction
    MessageQueue.js:306:47
<unknown>
    MessageQueue.js:108:26
__guard
    MessageQueue.js:269:6
callFunctionReturnFlushedQueue
    MessageQueue.js:107:17

Any help appreciated.

Better error message when providing call expression to passed in function

Right now the following is not allowed:

nameof<Project>(p => p.getDirectory())

The user must provide:

nameof<Project>(p => p.getDirectory)

The error message says Error: [ts-nameof]: Could not resolve string from expression: nameof<Directory>(d => d.getDirectories()), but perhaps it could say something along the lines of call expressions not being supported.

nameof type generics

This code currently returns "T" as result.

function myFunc<T>() {
    console.log(nameof<T>())
}
myFunc<String>()

Can we create new feature to nameof that could return name of type passed to generic function? (String in example provided)

Interface support

It would be good to support interfaces. This would mean that the person would have to use this library on the typescript before compiling (shouldn't be done on the original source files obviously).

So maybe this:

interface MyInterface {
    prop: string;
}

nameof<MyInterface>();

Compiles to:

"MyInterface";

[Question] Compatibility with jest-preset-angular

Has anyone used this library in a monorepo project with the jest-preset-angular preset, which configures ts-jest in a way that conflicts with this library.

I tried this which doesn't work (nameof is detected, but then the preset fails and so the tests don't run):

  globals: {
    "ts-jest": {
      tsConfig: '<rootDir>/tsconfig.spec.json',
      stringifyContentPathRegex: '\\.html$',
      astTransformers: [
        "ts-nameof",
        require.resolve("jest-preset-angular/InlineHtmlStripStylesTransformer"),
      ],
    }
  },

In fact is it even possible to use multiple presets or transformers?

Config instruction for webpack

I'm migrating my Aurelia project to webpack and am unsure of how to hook this plugin in with 'awesome-typescript-loader'. Do you have any clues?

Remove "this" in result of nameof.full

It's far easier to be able to do the following when using nameof in the same class. It's also impossible to reference private properties when referring interfaces

class Test{
  private x:Test;
  public y: Test;
  public z: string;

nameof(this.x) // "x"
nameof(this.x.y) // "y"
nameof.full(this.x.y.z) "x.y.z"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.