-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add support of isDefaultValueAvailable
and getDefaultValue
on PropertyInfo and Parameter types
#66
Comments
Detect if the parameter has initializer (that's how TypeScript compiler calls default value) is simple, if the parameter is rest parameter ( Imagine that the initializer of the parameter is class instantiation. If you reflect over such function/method from other file, you will not have reference to that class. So you have to import it dynamically, that means What if that class is not exported from that module? I'm able to get static values such as string, number and boolean literals as I do it in decorators. |
Hmm this will be the most problematic case IMHO. class Foo {
constructor(private _foo: any) {}
foo(foo: any = this._foo) {
}
} Initializer is |
I implemented the simple part in v1 (detection if the parameter is the rest parameter, if it has initializer and serialization of constant initializer). |
Your investigation around |
I think I have a lead. |
@leohubert class ParameterInfo {
....
+++ get initializer(): Initializer;
...
}
class Initializer {
isConstant(): this is ConstantInitializer;
isInstance(): this is InstanceInitializer ;
}
class ConstantInitializer extends Initializer {
get value(): any;
}
class InstanceInitializer extends Initializer {
get type(): Type;
getValue(): Promise<any>;
} Transformer just has to detect the type; maybe the constant arguments too? |
Hi all!
In a DI project, I need to know if a parameter in a class constructor function has a default value.
And also I need to be able to get the default value if needed.
This can be useful for classic methods or class properties.
The text was updated successfully, but these errors were encountered: