Parenthesis to switch between namespace and class?

Viewed 25

Working with legacy javascript I came across roughly the following js code

// module1.js
class Class {
    constructor() { console.log('hello') }
}
const exported = {
    Class: Class,
}
module.exports = exported

which is used like so in typescript

// module2.ts
import Module1 from './module1'

class Subclass extends Module1.Class { // <<
    constructor() {
        super()
    }
}

here vscode shows an error and the following type hint

(alias) const Module1: {
    Class: typeof Class;
}
import Module1
----------------------------------------
Cannot find namespace 'Module1'. ts(2503)

The thing I am curious about is after playing around I added parenthesis like so

class Subclass extends (Module1).Class {

and vscode no longer shows the error. What is this error and what is the meaning of those parenthesis? I couldn't find anything regarding namespaces, import aliases, ...

There is by the way no error when compiling with tsc, the code works either way.

some relevant parts of tsconfig (nodejs, ts 4.8.2)

    "target": "es2019",
    "module": "commonjs",
    "allowJs": true,
    "checkJs": false,
    "esModuleInterop": true,
0 Answers
Related