ts-nameof icon indicating copy to clipboard operation
ts-nameof copied to clipboard

Optional chaining?

Open w0nche0l opened this issue 5 years ago • 3 comments

I have an interface that looks like this:

interface A {
  optObject?: {
    propertyA?: string;
    propertyB?: string;
  }
}

and I'm trying to get the name "propertyA" by doing:

nameof<A>(a => a.optObject?.propertyA)

but I'm getting the following error: Unhandled node type (OptionalMemberExpression) in text: f.writerSettings?.autoSave

Am I doing this wrong or is optional chaining members not supported currently?

Also, thank you so much for this library, it makes refactoring typescript 1000% easier, easily one of the best libraries I've worked with.

w0nche0l avatar Mar 06 '20 23:03 w0nche0l

Not implemented yet. Will do soon!

dsherret avatar Mar 07 '20 00:03 dsherret

Temporary workaround when using Babel (should work fine with TS compiler) is to change this:

nameof<A>(a => a.optObject?.propertyA)

To this:

nameof<A>(a => a.optObject!.propertyA)

By the way, @w0nche0l, I am happy the library has been useful for you. Thank for the compliments! 🙂

dsherret avatar Mar 07 '20 20:03 dsherret

ah i completely forgot about the !. operator, that should work for now!

w0nche0l avatar Apr 12 '20 00:04 w0nche0l