Given the project described below, I get the following errors:
[ts] Cannot use 'new' with an expression whose type lacks a call or construct signature.
[tslint] Module 'Enums' is not listed as dependency in package.json (no-implicit-dependencies)
The folder structure of the project I have open in VS Code:
root/
-- tsconfig.json
-- src/
---- web/
------ src/
-------- ts/
---------- Navbar.ts (with exported namespace "Navbar")
---------- Shared/
------------ Other.ts
My tsconfig.json:
{
"compilerOptions": {
"baseUrl": "./src/web/src/ts/"
}
}
Navbar Module in Navbar.ts:
export namespace Navbar {
export class NavbarHandler {
...
}
}
Importing Navbar in Other.ts:
import { Navbar } from "Navbar";
const navbar = new Navbar.NavbarHandler();
As far as I can tell, my baseUrl is correct and is being recognized by VS Code - as VS Code shows the correct module path for Navbar when i hover over "Navbar"
in Other.ts.
Have I made a mistake? Is there something I'm not accounting for or I'm missing in my config?
You have this error because of no-implicit-dependencies
rule in your tslint config.
Currently there is no option to configure this rule to work with relative path. So, if you want to work with relative paths - you would need to disable this rule. Put "no-implicit-dependencies": false
in your tslint.json
file.
Here are on-going discussions about making this rule be configurable: https://github.com/palantir/tslint/issues/3364, https://github.com/palantir/tslint/issues/3483
Here you also can find some hacky workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With