dsherret / ts-nameof

nameof in TypeScript
MIT License
492 stars 23 forks source link

Support nameof.full<Array<T>>() to "Array<T>" #99

Open deveitrust opened 4 years ago

deveitrust commented 4 years ago

In documentation:

nameof.full<Array<MyInterface>>(); Transforms to: "Array";

How can i get it work and transform into: "Array<MyInterface>" ?

dsherret commented 4 years ago

Need to think about this more, but right now the only way to do it is to do:

`${nameof(Array)}<${nameof(MyInterface)}>`

The reason this isn't done by default is because c# doesn't do this with nameof.


Basically whatever solution is chosen need to ensure there's still a way to not include type arguments.

deveitrust commented 4 years ago

Need to think about this more, but right now the only way to do it is to do:

`${nameof(Array)}<${nameof(MyInterface)}>`

The reason this isn't done by default is because c# doesn't do this with nameof.

Thank you for the fast response, actually your solution will work but with some improvement (because Array is generic interface it require parameter to be passed like: ${nameof(Array<void>)}<${nameof(MyInterface)}>

In anyway it is not elegant way to make it work, so hope you will add new feature, it will help a lot. Thank you!

dsherret commented 4 years ago

No problem! Yeah, maybe something like nameof.fullWithArgs<Array<MyInterface>>()?

Ooops.. you're right. I messed up that example in other ways too. Should be:

`${nameof<Array<void>>()}<${nameof<MyInterface>()}>`
deveitrust commented 4 years ago

No problem! Yeah, maybe something like nameof.fullWithArgs<Array<MyInterface>>()?

Ooops.. you're right. I messed up that example in other ways too. Should be:

`${nameof<Array<void>>()}<${nameof<MyInterface>()}>`

Yes please, it would be great, and will save tons of time and help to write elegant ts code. If it is not possible to extend nameof.full functionality to support arguments, then you could create separate function like nameof.fullWithArgs<Array<MyInterface>>() or nameof.all<Array<MyInterface>>() or nameof.complete<Array<MyInterface>>() or with any other naming.

Thank you!