I am trying a basic ts setup to use top-level await and it works (prints the result from the api) if I run tsc && node dist/main.js
, but when I run npx tsc
- it does nothing but generate dist
folder with main.js and main.js.map.
I am trying to understand why npx tsc doesn't work and what I am doing wrong.
Here is my setup
tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true,
"preserveConstEnums": true,
"module": "es2022",
"target": "ES2021",
"outDir": "./dist",
"strict": true,
"sourceMap": true,
"types": [
"node"
],
"moduleResolution": "Node",
"allowJs": true
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
}
src/main.ts
import axios from "axios"
let api = 'https://www.boredapi.com/api/activity'
let response = await axios.get(api)
console.log(`You could ${response.data.activity}`)
```