-
Notifications
You must be signed in to change notification settings - Fork 8
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
类属性装饰器需要初始值 #4
Comments
现在这样的写法是比较合理的,放到 constructor 里指的是什么样的形式? ignore 的问题可以通过修改规则配置来解决,毕竟 lint 本身的目的是为了防止代码出现静态检查可以发现的错误,如果此处明确是使用 |
但是不能完全约束用户用构造函数初始化属性,改变配置也可以 |
@hyj1991 类似这种形式,nest 和 angular 没少用 import { Injectable, Inject } from '@nestjs/common';
@Injectable()
export class HttpService<T> {
constructor(@Inject('HTTP_OPTIONS') private httpClient: T) {}
} 不过确实不能强迫用户这么用,太拉了 |
改 ignore 配置的话,用户工程的 tsconfig 也需要这么配,得再看看友商都是怎么玩的,有没更优解法 |
或者初始化的时候 extend 我们一个公共的 tsconfig?后面应该会提供工具生成脚手架都默认类似这样的模板: {
"extends": "@artus/tsconfig",
"compilerOptions": {
}
}
|
其实可以参考spring的做法,有 Value 装饰器 |
如这部分代码所示,Inject 在类属性上生效是会被默认的 TS 规则视为未初始化,考虑处理:
https://github.com/artusjs/core/pull/10/files/79a727d28b9546ec2d3fba638c1d0b08b746f493#diff-16a8f18a1e6d24ab6125db9b965edc8d7970d184e44ada35f3ccbf71a21670a4R13
The text was updated successfully, but these errors were encountered: