TypeScript: is there something like a __FILE__ compiler macro?

From other languages ​​I know __FILE__ or similar expressions (for example: in PHP - a constant, in C - a preprocessor macro), which are replaced by the current path to the source file. Is there anything similar in TypeScript?

+5
source share
2 answers

If you are creating a node application

 __dirname 

Gives you the current module directory path

https://nodejs.org/docs/latest/api/globals.html#globals_dirname

+1
source

There is currently a function request for this, see https://github.com/Microsoft/TypeScript/issues/4892

From what I see, it has not yet been implemented.

You can create one workflow by adding your custom comments (e.g. / ** @ compile-if * /) and then using the Gulp / Grunt task to convert the code after the actual Typescript compilation.

+1
source

Source: https://habr.com/ru/post/1247192/


All Articles