I am trying to split my project into two separate projects and then reuse files between them. Now that I am using my Helper class as an external module, I am getting errors trying to use it in my test. Am i importing/exporting the module incorrectly?
- Cannot use namespace 'Helper' as a type
- Cannot use 'new' with an expression whose type lacks a call or construct signature.
main project
test.ts
import Helper = require('sub-project');
describe(`Test Description`, () => {
let helper: Helper; // error - cannot use namespace Helper as a type
before(async () => {
helper = new Helper(); // error - Cannot use 'new' with an expression whose type lacks a call or construct signature.
await helper.myFunction(xx, xx);
});
package.json
"devDependencies": {
"sub-project": "file:../../sub-project/e2e"
}
sub-project
app.ts
export {Helper} from './src/xx/helper’;
helper.ts
export class Helper {
}
package.json
"name": "sub-project",
"main": "app.ts"
tsconfig.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "lib",
"rootDir": ".",
"target": "es5",
"module": "commonjs",
"types": [
],
}
}
import Helper = require('sub-project');
why notimport { Helper } from './src/xx/helper';
? – Przemyslaw Jan Beigertnode_modules
, you should always use require? – user6086008