You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want foo function to generate ts code depending on the generic type passed when calling this function.
Is it possible for ts-morph to get the generic type of the wrapping function?
functionfoo<T>(){// ts-morph methods to get the current generic type, e.g. "string" in case called `foo<string>()`// ...}
In case it is not possible, is there other way to pass the type to the ts-morph inside the body of the function? Maybe through the type of an argument or something else?
Thank you!
The text was updated successfully, but these errors were encountered:
Hey @yavulan, if I'm understanding correctly, I believe probably the easiest way to solve this is to just change all the the call sites like foo<number>() to have the necessary code. I think you could just replace the expressions with an immediately invoked function containing the specify logic (ex. replace foo<string>() with (() => { /* your code goes here that deals with string */ })()). The node.replaceWith(writer => {}) function will be useful here.
By the way, here's an example that uses the compiler api directly and babel to change the call sties: https://github.com/dsherret/ts-nameof (doesn't use ts-morph)
Thank you. ts-nameof example is very close to what I was looking for. It's a pity microsoft/TypeScript#14419 is still not implemented.
Btw, I went through some issues on the issue tracker for ts-morph. And it's incomparable to most issue trackers for popular libraries - this issue tracker is very welcoming and useful. THANK YOU!
Thank you for this awesome project!
I want
foo
function to generate ts code depending on the generic type passed when calling this function.Is it possible for
ts-morph
to get the generic type of the wrapping function?In case it is not possible, is there other way to pass the type to the ts-morph inside the body of the function? Maybe through the type of an argument or something else?
Thank you!
The text was updated successfully, but these errors were encountered: