Search code examples
typescriptextendscript

How can I tell typescript to include a line verbatim in js without parsing it


I’m writing an app in typescript to compile to adobe extendscript (an es3-based javascript syntax).

I am trying to use the extendscript-only syntax

#include "path_to_file";

which is not valid typescript (and not even valid javascript). I would like to tell typescript to just include it as-is, without parsing it.

I know about @ts-ignore, and @ts-except-error, but though these prevent typescript from throwing an error, they don’t prevent it from messing the line while transpiling it. In the end the output line is :

#include;

which kinds of defeats the purpose.

Is it possible to tell typescript not to parse next line and to just include it as-is in javascript code ?

(otherwise I’m going to have to resort to some dark Makefile / cat magic)


Solution

  • You can achieve what you're looking for by using the alternative extendscript-directive syntax that uses //@ instead of #. The fact it's effectively a comment means typescript will ignore it, but extendscript still sees it.

    So change your:

    #include "path_to_file";
    

    to be:

    //@include "path_to_file";