nameof with arrays
See original GitHub issueHello!
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
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
c# - Is it possible to imply the name of the parameters of a ...
I thought I could make use of the new c# 6 operator nameof to build a dictionary of key/values implicitly from a params...
Read more >Working With Arrays In C#
Array in C# represents a collection of items. C# Array class is used to create an array in C# and .NET. In this...
Read more >Get the name of an array : Name « Reflection « Java Tutorial
Get the name of an array : Name « Reflection « Java Tutorial ; 7.14.1. Getting the Name of a Member Object ;...
Read more >Name an array constant - Microsoft Support
To name an array constant, click Formula, then Define Name. Enter a name and the constant, then you can use the constant as...
Read more >C# Array: How To Declare, Initialize And Access An Array In C#?
An array can be declared by using a data type name followed by a square bracket followed by the name of the array....
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
@intnovaction that output seems correct to me. I don’t believe nameof should replace any identifiers with their constant values or current value in an iteration. Note that
nameof
is evaluated before the program is run so doing it in an iteration wouldn’t be possible. I think in this situation you would want to get the string and then add the value into it:@intnovaction couldn’t think of a reason not to do this. This is released in 0.9.2. I increased the minor revision only because this is a very minor change with no api changes.
So yeah, just upgrade and use
nameof.full(elem.items[0].prop1);
and it should work well for you. Let me know if you have any other issues or find any problems and I’ll take a look into it.