46π
This is a lint error caused by the no-namespace lint rule.
If you find the rule helpful and want to keep it, you will need to modify your code by replacing namespaces with imports and exports. The documentation of the rule provides details on what changes are needed for a fix.
If you like the rule but want to disable it for this specific line, you can add the following comment just above it:
// eslint-disable-next-line @typescript-eslint/no-namespace
If you dislike the rule and wish to disable it entirely, you can edit your .eslintrc file and add the following line:
rules: {
"@typescript-eslint/no-namespace": "off"
}
41π
Fixing the Error in TypeScript
To fix this error, instead of:
export namespace InternalThings {
export function myFunction() {
}
export class MyClass {
}
}
import { InternalThings } from './internal-things';
InternalThings.myFunction();
you can make all the members of the namespace directly accessible:
export function myFunction() {
}
export class MyClass {
}
Now, you can import it using the following syntax:
import * as InternalThings from './internal-things';
InternalThings.myFunction();
The main advantage of this approach is that users of your module can choose to import only what they need or give your module a custom name:
import * as CustomModuleName from './internal-things';
CustomModuleName.myFunction();
import { MyClass } from './internal-things';
let field = new MyClass();
2π
The error is being reported by eslint. To resolve this issue, you can either exclude the β@typescript-eslint/no-namespaceβ rule in the eslint configuration or update your code to use ES6 syntax.
The usage of custom TypeScript modules (module foo {}) and namespaces (namespace
foo {}) is considered outdated in organizing TypeScript code. The preferred method now is to use ES2015 module syntax (import/export).
Please refer to the following link for more information: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-namespace.md
Read more interesting post
- The login is invalid due to a mismatch in the username and password, as error 535-5.7.8 indicates that they are not accepted.
- The npm install command in Node.js encounters an error C2373 when used in conjunction with Visual Studio 2015 Update 3. Rewrite this sentence and simply return it rewritten without any additional text.
- How can I verify and update the Node.js version on Ubuntu?