Description
TypeScript Version: 4.0.2
Search Terms: getMutableClone cloneNode createThrow createNew NodeFactory
Code
ts.factory.cloneNode(someNode);
Expected behavior:
The compiler should compile the code just fine without error.
Actual behavior:
The compiler signal an error saying that the cloneNode function does not exists on NodeFactory.
On ts.getMutableClone the deprecated notice says we should use factory.cloneNode instead. Unfortunately, there is no cloneNode function defined on NodeFactory according to the declaration file (typescript.d.ts).
However, if I trick the compiler with the following code, I see that a cloneNode function do exist on the object that implements the NodeFactory interface at runtime.
(ts.factory as any).cloneNode(someNode);
Related Issues:
I have seen a few deprecated notices that are a bit misleading on many functions in the ts namespace. I have not checked all functions, but to name a few:
- createThrow says to use factory.createThrow instead of factory.createThrowStatement.
- updateThrow says to use factory.updateThrow instead of factory.updateThrowStatement.
- ...
- The same goes for createNew, updateNew, createTry, updateTry