-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update documentation to warn that @Inject
via constructor is unsupported on vite 5.0.11 and above
#182
Comments
I did notice this PR that has been in the works since September. #175 v3.0 looks like it will stop using the legacy decorators implementation, removing the need for the |
Hey @zacharyweidenbach Indeed v3 will stop using the legacy decorators implementation. But in fact I don't think v2 actually needs Few things to keep in mind: |
@zacharyweidenbach Do you have experience writing an SWC plugin? I think adapting our existing Babel plugin to an SWC plugin similar to this should be fairly easy. Edit: I usually miss notifications on GitHub by available on Discord |
I don't have much experience with writing SWC plugins. I can take a swing at it. Before I get too far though, I want to confirm that what I'm trying to do with class injection should work. This is what I want to do but it seems fail to inject the dependency. At runtime, the @Singleton()
@Graph()
export class ApplicationGraph extends ObjectGraph {
@Provides()
store(): Store {
return getStore();
}
}
@Inject(ApplicationGraph)
export class CreateOneMethod {
constructor(@Inject() private store: Store) {
}
public execute(todoTitle: string, todoId: string) {
this.store.save(todoTitle, todoId);
}
}
@Singleton()
@Graph({ subgraphs: [ApplicationGraph] })
export class TodoService extends ObjectGraph {
constructor(@Inject() private createOneMethod: CreateOneMethod) {
super();
}
@Provides()
createOne(): CreateOneMethod['execute'] {
return this.createOneMethod.execute;
}
} |
@zacharyweidenbach Are you using Obsidian's Babel plugin If not, then you'll have to adapt your code slightly: @Singleton() @Graph()
export class ApplicationGraph extends ObjectGraph {
@Provides({name: "store"})
store(): Store {
return getStore();
}
@Provides({name: "createOneMethod"}
createOneMethod({store}) {
return new CreateOneMethod(store);
}
}
@Singleton() @Graph({ subgraphs: [ApplicationGraph] })
export class TodoService extends ObjectGraph {
@Provides({name: "createOne"})
createOne({createOneMethod}): CreateOneMethod['execute'] {
return this.createOneMethod.execute;
}
} Notice that each provider needs to explicitly specify a |
I'm not sure @Injectable(ApplicationGraph)
export class TodoService {
@Inject("createOneMethod") createOneMethod: createOneMethod!;
createOne(): CreateOneMethod['execute'] {
return this.createOneMethod.execute;
}
} |
Closing. After a conversation in discord. It was discovered that I was incorrectly using class injections with graphs. Class dependencies are not recursively resolved in the same way that graphs are. However, for vite, I did need to add a plugin that I did not see in the documentation in order to prevent compile time errors from being thrown due to field injection in a class, via
Thanks to guyca for being so responsive and helpful! |
Description
Vite 5.0.11 and greater uses
esbuild
which cannot support theemitDecoratorMetadata
in thetsconfig.json
because this feature requires a type system which esbuild does not provide.vitejs/vite#4884 (comment)
vitejs/vite#15565
The workaround might be to use a different transpiler than the official
vite-plugin-react-swc
but I have not confirmed. Regardless, this would be helpful to know beforehand in the documentation.The text was updated successfully, but these errors were encountered: