Currently, I have set up a basic TypeScript configuration to utilize top-level await. It functions as expected and prints the result from the API when I execute tsc && node dist/main.js
. However, when I use npx tsc
, it only generates a dist
folder with main.js and main.js.map without executing anything. I am puzzled by why npx tsc fails to work and what mistake I might be making.
Below is the configuration I am working with:
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}`)