Issue
I use spring MVC to pass data from java to javascript and start a webcomponent. To grab the variables with javascript I had this line in the html file:
<script th:inline="javascript">
const data = /*[[${data}]]*/ '';
</script>
This worked great! I was able to use the variable in every .js file I added to the html. But now I switched to Typescript and its not compiling because I doesnt see the variable. Is there a way around this?
Btw.: The variable is a rather complex object with subobjects and so on.
Thanks in advance!
Solution
You have to declare it in a .d.ts
file:
declare const data: DataInterface;
https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
Answered By - Roberto Zvjerković
Answer Checked By - Gilberto Lyons (JavaFixing Admin)