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

What’s the difference between internal and external modules in TypeScript?

Sections 9.3 and 9.4 of the specification explain this more clearly. I’ll reproduce here some of the examples given in those sections. External modules Suppose the following code is in main.ts. import log = module(“log”); log.message(“hello”); This file references an external module log, defined by whatever log.ts exports. export function message(s: string) { console.log(s); } … Read more

How to make a class implement a call signature in Typescript?

Classes can’t match that interface. The closest you can get, I think is this class, which will generate code that functionally matches the interface (but not according to the compiler). class MyType implements MyInterface { constructor { return “Hello”; } } alert(MyType()); This will generate working code, but the compiler will complain that MyType is … Read more

TypeScript – wait for an observable/promise to finish, and return observable

The problem is that we convert observable into different type… with .subscribe – while we should not (it does not return observable) public makeRequest = (): Observable<any> => { return this.myObservable().subscribe( … // this is wrong, we cannot return .subscribe // because it consumes observable and returns ISusbcriber ); } When we have an observable… … Read more