Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript: is there something like __FILE__ compiler macro?

Tags:

typescript

From other languages I know __FILE__ or similar expressions (for instance: in PHP a constant, in C a preprocessor macro) that are replaced with the current source file path. Is there anything like this in TypeScript?

like image 544
BlueM Avatar asked Apr 15 '16 08:04

BlueM


2 Answers

If you are creating a node application

__dirname

Will give you the current module directory path

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

like image 70
Jonatin Avatar answered Nov 06 '22 06:11

Jonatin


There is currently feature request for that, see https://github.com/Microsoft/TypeScript/issues/4892

From what I am seeing it is not implemented yet.

One work-around can be, adding your custom comments( for example /** @compile-if */) and then using Gulp/Grunt task to transform code after actual Typescript compilation.

like image 2
Stoyan Stoyanov Avatar answered Nov 06 '22 06:11

Stoyan Stoyanov