6 ms·
Good write-up and it is quite a neat feature. We wanted to use it in the library I work on to model how a method of our class mutates an argument to add new pro
by tomduncalf 4y ago
Good write-up and it is quite a neat feature. We wanted to use it in the library I work on to model how a method of our class mutates an argument to add new properties to it (IIRC, it was a little while ago), but hit an issue that you need to explicitly type the instance of the class for this to be usable – that is, a user can't write "const assertingInstance = new AssertingClass()" but instead has to write "const explicitAssertingInstance: AssertingClass = new AssertingClass()". We decided that this was going to be too inconvenient for our users, and so pursued a different API direction.
I raised an issue and Ryan from the TS team gave a good explanation of why this is so, and why it's unlikely to change in the near future (performance penalty of doing the analysis required), but I thought I'd mention it in case anyone is looking to use this feature and might hit the same issues. The TS issue is https://github.com/microsoft/TypeScript/issues/47945 https://github.com/microsoft/TypeScript/issues/47945 if you'd like to see more details.