dsherret / ts-nameof

nameof in TypeScript
MIT License
492 stars 23 forks source link

Optional chaining? #100

Open w0nche0l opened 4 years ago

w0nche0l commented 4 years ago

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.

dsherret commented 4 years ago

Not implemented yet. Will do soon!

dsherret commented 4 years ago

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! 🙂

w0nche0l commented 4 years ago

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