Support `typeof import` as `nameof` generic
wh1t3cAt1k opened this issue · comments
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.
@wh1t3cAt1k yup, I'll get on it! Thanks for bringing this to my attention.
As a temporary workaround, you can assign the type to a type alias.
type YourModule = typeof import('./modules/ModuleName');
nameof<YourModule>(x => x.Foo)
@dsherret yeah, that's what I currently do! Thanks a lot!
Should be implemented now in 3.1.0. Let me know if not.