We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package.json
{ "name": "dead-simple", "dependencies": { "@opensumi/di": "^2.1.0", "reflect-metadata": "^0.2.2" } }
src/index.ts
import "reflect-metadata" import { Injectable, Autowired, Injector } from '@opensumi/di'; interface Drivable { drive(): void; } @Injectable() class Bike implements Drivable { drive() { console.log('Bike is driving'); } } @Injectable("Student") class Student { @Autowired('Drivable') mBike: Drivable; goToSchool() { console.log('go to school'); this.mBike.drive(); } } const injector = new Injector(); injector.addProviders( { token: 'Drivable', useClass: Bike }, { token: 'Student', useClass: Student } ); const student = injector.get('Student'); student.goToSchool();
expect log
go to school Bike is driving
but error
this.mBike.drive(); ^ TypeError: Cannot read properties of undefined (reading 'drive')
The text was updated successfully, but these errors were encountered:
原因 mako 使用默认的 assumption 配置
assumption.set_public_class_fields = false; assumption.set_class_methods = false;
相当于 swcrc 配置 ref
swcrc
"transform": { "legacyDecorator": true, "useDefineForClassFields":true <----- here
产物中
class Student { mBike; <----- 直接覆盖了 decorator 结果 goToSchool() { console.log('go to school'); this.mBike.drive(); } }
修改 useDefineForClassFields -> false
产物正常执行
Sorry, something went wrong.
Ref https://swc.rs/docs/migrating-from-tsc#usedefineforclassfields
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier
stormslowly
Successfully merging a pull request may close this issue.
package.json
src/index.ts
expect log
but error
this.mBike.drive(); ^ TypeError: Cannot read properties of undefined (reading 'drive')
The text was updated successfully, but these errors were encountered: