I have a module containing various helper classes, each defined in their own files such as controller.ts
and stateService.ts
. To export all of them, I understand that creating an index.ts
file that imports and exports them all serves as the interface to the module.
Typically, the structure of my files is as follows:
export default class Controller {
public state: stateService; // This will be important later on
// other class elements
}
And in my index.ts
file, it simply lists these classes:
export { default as Controller } from './controller';
My tsconfig.json
is configured like this:
{
"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 created a sample project to test the module locally using npm link
:
export default class OwnerController extends Controller {
foo() {
this.state.get(bar);
}
}
When trying to use the Controller
class in a dependent project and access the state
property, I encounter the following error:
[ts] Property 'state' does not exist on type 'OwnerController'. [2339]
Similarly, class methods also result in this error:
[ts] Property 'start' does not exist on type 'CarExampleApp'. [2339]
Could anyone provide guidance on what I might be doing incorrectly? (thank you!)