Relative Content

Tag Archive for node.jstypescript

Warning: Detected unsettled top-level await

The following code results in error Warning: Detected unsettled top-level await. I don’t understand why all of a sudden this block is throwing error when it was working just an hour ago. Didn’t make any changes to my dev environment.

I can’t make my code work using import on routes, but require does

import path from “path”; import express from “express”; import { performance } from “perf_hooks”; import fs from “fs”; const basename = path.basename(__filename); class Routes { async loadRoutes(app: express.Application) { const t1 = performance.now(); return new Promise<void>(async (resolve, reject) => { const files = fs.readdirSync(__dirname) .filter((file: string) => { return ( file.indexOf(“.”) !== 0 && file.indexOf(“..”) […]

Is there a way to use a function to generate a union type?

I’m building a telegram bot with TypeScript and GrammyJs. I have some commands that I will be using many times and I also need to use the names of these commands inside my code as a union type. How can I create a function that can generate that union type?

no such file or directory, scandir ‘i’

My this code is supposed to read a path to a directory, then read the JSON files in that directory then package them up in one file. But some how the function is reading every char of the the directo`ry path as a directory or file path like the individual letters.