Typescript injection with specifying types

Consider I have this Typescript code, with the class DB imported from a library:

class DB {
run(query:String) {
// implementation

const db:DB = new DB();
db.run("some query code ...");

Is it possible to inject a specific language into the query String (to highlight syntax for "some query code ..."), specifying that the injection should happen only for the "run" method of class DB (imported from a specific package)?
I've seen that JS injections work for TypeScript, however they don't provide a clear API to specify methods of specific classes, and JSElementPattern_Capture jsArgument() is insufficient - there is no method like definedInClass() to specify the type.

Is using types possible while injecting stuff into TypeScript?


1 comment
Comment actions Permalink

Hi. The problem is that the "class name" information cannot be fetch directly from the PSI tree because it requires resolution for variables.

You can provide injection using some heuristics (e.g. inject the languages to all strings inside "db.run") or you can resolve the variable locally and check the type. The closest code that I have found is in


Unfortunately it doesn't resolve variables but check that the injection place is a property in "@Component()" decorator.

If you need more information about local resolution please let me know



Please sign in to leave a comment.