This is the error that I get
./src/core/providers/todoApi/TodoApiProvider.ts 10:14 Module parse failed: Unexpected character '@' (10:14) File was processed with these loaders:
- ./node_modules/react-scripts/node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
- ./node_modules/babel-loader/lib/index.js You may need an additional loader to handle the result of these loaders. | class TodoApiProvider {
constructor(@inject(TYPES.HttpClient) | httpClient) { | this.httpClient = void 0;
TodoApiProvider.ts
class DefaultTodoApiProvider implements TodoApiProvider {
private httpClient: HttpClient;
// @inject(TYPES.HttpClient) return error
constructor(@inject(TYPES.HttpClient) httpClient: HttpClient) {
this.httpClient = Dependency.get(TYPES.HttpClient);
}
async getTodoById(id: string) {
const data = await this.httpClient.get(
`https://jsonplaceholder.typicode.com/todos/${id}`
);
return data;
}
}
decorate(injectable(), TodoApiProvider);
export default DefaultTodoApiProvider;
If I put @inject(TYPES.HttpClient)
above private httpClient: HttpClient;
it will get another error Cannot access 'TYPES' before initialization
.
.babelrc
{
"presets": [
...,
"@babel/preset-typescript"
],
"plugins": [
...,
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
],
"env": {
"test": {
"plugins": [
"transform-require-context",
"babel-plugin-transform-typescript-metadata",
"babel-plugin-parameter-decorator"
]
}
}
}
tsconfig.js
{
"compilerOptions": {
...,
"emitDecoratorMetadata": false,
},
}