#Inline typescript

3 messages · Page 1 of 1 (latest)

errant hazel
#

Is it possible to write inline typescript after adding define:vars to the script tag?

atomic kayakBOT
#

Hi @errant hazel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro does support TypeScript, and you can write TypeScript code directly inside your Astro component. However, the define:vars directive is used to pass server-side variables from your component frontmatter into the client <script> or <style> tags. When you use define:vars on a <script> tag, it implies the is:inline directive, which means your scripts won’t be bundled and will be inlined directly into the HTML.

The is:inline directive tells Astro to leave the <script> or <style> tag as-is in the final output HTML. The contents will not be processed, optimized, or bundled. This limits some Astro features, like importing an npm package or using a compile-to-CSS language like Sass.

Therefore, while you can write TypeScript in your Astro components, it's not clear from the provided sources whether TypeScript would be processed correctly in an inline script with the define:vars directive.

For more information, you can refer to the following sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: