#How to import typescript string[] to inline javascript in .astro file?

1 messages · Page 1 of 1 (latest)

elder cosmos
#

I'm storing my string[] in file.ts

export const themeList:string[] = ['cool', 'ugly', 'awesome']

My .astro file looks like this (:

---
---

<!doctype html>
<html lang='en'>
  <script is:inline>
    function setRandomTheme(x) {
      // here I wan't to have access to all items from that array
    }
  </script>
  <slot/> // here, inside slot, I will have button with onclick="setRandomTheme()"
</html>

The problem I have: If I use import { themeList } from '../file.ts inside script tag, I will be not able to call setRandomTheme() because <script is:inline> will be just <script>.

#

How to import typescript string[] to inline javascript in .astro file?

sour agate
#

you might want to attach your event handler another way, for example using an id and addEventListener

elder cosmos
#

I wanted to avoid that, but... maybe that will be the best way