Get method name from within a typescript method

前端 未结 5 1054
陌清茗
陌清茗 2021-01-04 07:33

I want to get the name of the current method from within an instance method of a class in Typescript.

(Pseudocode, doesn\'t work):

class Foo {
    ba         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 07:49

    Keep in mind that during compilation and minification you might lose the actual name of what you're trying to use. You might consider looking into the ts-nameof babel macro that reads the name of virtually anything during compilation and returns it's actual string representation.

提交回复
热议问题