What are the proper typescript types for addEventListener mousemove and its event argument?

What are the proper typescript types for addEventListener mousemove and it’s event argument? Being explicit will set you free: onMouseMove: { (event: MouseEvent): void } = (event: MouseEvent) => { } Or, let TypeScript infer it from assignment 🌹: onMouseMove = (event: MouseEvent) => { }

tsc – doesn’t compile alias paths

TSC compiler alone can’t resolve the alias paths. So in order to make it work you will be required to install additional dev package npm install –save-dev tsc-alias tsc-alias is for replacing alias paths with relative paths after typescript compilation of tsc compiler because the compiler alone can’t resolve the alias paths After that you … Read more

Declare dynamically added class properties in TypeScript

The problem is that you’re adding the new properties at runtime and the compiler has no way of knowing that. If you know the property names in advance then you can do this: type Json = { foo: string; bar: string; } … const myInstance = new MyClass(someJson) as MyClass & Json; console.log(myInstance.foo) // no … Read more

This is not the tsc command you are looking for

The problem in my case was that I had installed tsc package instead of the correct typescript. From https://www.npmjs.com/package/tsc: Use typescript to get access to the tsc CLI command. The fix is: npm uninstall tsc npm install -D typescript Commands like npx tsc –version will still run because typescript provides the tsc executable.

Typescript noEmit use case

It’s used when tsc is used only for type checking, not for compilation. That’s the case when some other tool (like Webpack, Parcel or Rollup) is responsible for compiling your code. If you are interested in running your code in an interactive mode, look into ts-node or ts-node-dev.

error TS6059: File is not under ‘rootDir’ .. ‘rootDir’ is expected to contain all source files

What is rootDir? rootDir is set to a root folder, that contains all your source files. If not specified, TS will automatically choose a suitable parent folder of all inputs. rootDir also determines the output directory. What does the error mean? My guess is you have an import statement for logging.ts somewhere in notifier-server: import … Read more

How to get tsc to Resolve Absolute Paths when Importing Modules using baseUrl?

The answer comes from @DenisPshenov’s comment in one of the answers. It’s buried, so I’ll provide it here… Tell Node where the base url is with NODE_PATH environment variable so that it can resolve absolute paths: Linux / macOS NODE_PATH=dist/ node ./dist/index.js Windows Powershell $env:NODE_PATH=”dist/” node ./dist/index.js