In summary: Is there a method to determine whether a typescript parameter is mandatory and/or has a preset value?
Expanding further: Imagine I have the code snippet below:
//Foo.ts
class Bar {
foo(required:string,defaultValue:number=0,optional?:boolean) {
...
}
}
I am interested in retrieving the following details for each parameter:
- The name
- The data type
- Is it obligatory?
- Does it come with a default value?
While I have effectively utilized method decorators alongside the TypeScript reflection API to obtain the data types of the parameters, as well as referenced this approach to retrieve their names, I have not yet discovered a technique to identify if a parameter is mandatory or has a default value.
I acknowledge that the typescript compiler can be accessed from within typescript itself. Therefore, I am curious if there exists a means to utilize the parse tree of the compiler to ascertain whether a parameter is compulsory and/or has a predefined value?
How would this process unfold?