I have a module which is a collection of helper classes, each defined in their own files: controller.ts
, stateService.ts
and so on. From what I gather the way to have them all exported is to create an index.ts
that imports all of them and then exports them (serving as an interface to the module).
By and large my files look something like this:
export default class Controller {
public state: stateService; // This will become relevant in a moment
// other things in the class
}
And my index.ts
is a list of these:
export { default as Controller } from './controller';
My tsconfig.json
is like so:
{
"compilerOptions": {
"moduleResolution": "node",
"noImplicitAny": true,
"preserveConstEnums": true,
"outDir": "dist",
"sourceMap": true,
"noEmitOnError": true,
"target": "es6",
"module": "commonjs",
"declaration": true,
"experimentalDecorators": true,
"suppressImplicitAnyIndexErrors": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "tests", "src/**/*.spec.ts"],
"types": ["jest"]
}
Now I have an example project to test the module locally with npm link
:
export default class OwnerController extends Controller {
foo() {
this.state.get(bar);
}
}
I get the following error when I try to use my Controller
class in a dependent project and access the state
property:
[ts] Property 'state' does not exist on type 'OwnerController'. [2339]
In much the same way, class methods also get this error:
[ts] Property 'start' does not exist on type 'CarExampleApp'. [2339]
Can anyone advise as to what I'm doing wrong? (thanks!)