tc39/proposal-decorators

Way to distinguish the current decorator implementation from the others at runtime?

Closed this issue · 3 comments

I'm a library creator and so far I have to deal with making a library that has to work with the TS experimental decorator implementation, the old babel decorator implementation, the new babel decorator implementation and soon this one.

Given I'm not in control of which implementation the library user will use in their transpiler/runtime, I basically have to "hack away" a function that uses the difference in argument shapes to know which is the implementation being used.

As a suggestion, could this proposal add a field in the context object that can be easily checked to distinguish this implementation from the others? (So library authors don't have to rely on the shape of the arguments once more to distinguish it from the others)

You should be able to very easily duck-type the context argument. In TypeScript the second argument will be a string or symbol.

I know I can duck-type it (that's what I have done for all the other implementations so far), I was just hoping I could avoid it for once if possible 😄

Unfortunately duck typing is the only way to distinguish, there is no other way if you want to be compatible with all decorators transforms.