Search code examples
lessconstantstypescript

Constants in LESS and Typescript


Sometimes I want to define a constant, which is to be used in both LESS and Typescript. What is the best way for achieving that?


Solution

  • I'm not sure you have any common ground here - unless you are going to parse the variable by reading one language from the other.

    You could use a server-side language to inject the constant into both a LESS file and a TypeScript file, but this could be overkill.

    One possible solution would be to detect the value that was used in the LESS file by inspecting the DOM result, for example if you had a width in LESS defined as a constant, you could inspect the width of the element in TypeScript to get the result.