Skip to content

Tag: typescript

Convert json from file to map not working

i have this code which gives the error “Error: Uncaught (in promise): TypeError: this.weekMap.get is not a function”. Why weekMap is not recognized as a Map object? The Json file contains: } Answer You are not converting the variable weekMap to a Map object correctly. Try the Object.entries function:

Variable ‘value’ is used before being assigned

My code: And got this: I found this very odd, as I had seen other similar problems that either used a callback or a Promise or some other asynchronous method, while I used just a synchronous for loop. ———————————- Some update ———————— Answer Use the non-null assertion operator to ensure that “its operand is non-null and non-undefined in contexts where

React.js builds with Vite does not include service-worker.ts

I am using Vite to build an SPA with React (typescript), and I am trying to register a service-worker. I am registering the script as type module, and service-worker.ts sits at src/web-worker/service-worker.ts. There is also a tsconfig.json at src/web-worker Everything works in Dev, but when it’s built, src/web-worker/service-worker.ts is not replaced with anything equivalent. Any suggestions? index.html src/web-worker/service-worker.ts src/web-worker/tsconfig.json Answer

typescript template literal in interface key error

Typescript v4.4.3 Reproducible Playground Example — What i’ve tried: I’ve confirmed that id in my code is a string. This happens when running tsc not just in VSCode warnings Is there some restrictions of using template literals or anything else I can investigate to diagnose this? Answer The issue is that computed keys of types that are not single literal