Comments (15)
@carloszimm
Implemented in [email protected]
and [email protected]
.
from tst-reflect.
it only prints the first signature (overload) of the function
Hello @carloszimm,
I have to change the Type.function: FunctionInfo
to something like Type.getSignatures(): ReadonlyArray<FunctionInfo>
.
FYI @avin-kavish
from tst-reflect.
type.getConstructors()
returns list with constructor or its overloads.
type.getMethods()
returns list of methods with their overloads. Each overload is treated the same as method itself. Overload represents callable method. You can detect overloaded methods by grouping methods by name.
StackBlitz demo.
export class SomeClass {
constructor();
constructor(a?: boolean);
constructor(b?: string);
constructor(a: boolean, b?: string);
constructor(aOrB?: boolean | string, b?: string) {}
someMethod(a?: boolean);
someMethod(b?: string);
someMethod(aOrB?: boolean | string) {}
someOtherMethod() {}
}
While writing the demo I figured out that method overloads does not work and we don't even have the unit test for that.
I've prepared the fix, I'll publish that in the evening.
This is the output from that demo running with fixed version:
Constructors:
┌─────────┬───────────────┬──────────────┐
│ (index) │ 0 │ 1 │
├─────────┼───────────────┼──────────────┤
│ 0 │ │ │
│ 1 │ 'a?: Boolean' │ │
│ 2 │ 'b?: String' │ │
│ 3 │ 'a: Boolean' │ 'b?: String' │
└─────────┴───────────────┴──────────────┘
Methods:
┌─────────┬───────────────────┬───────────────────┐
│ (index) │ 0 │ 1 │
├─────────┼───────────────────┼───────────────────┤
│ 0 │ 'someMethod' │ [ 'a?: Boolean' ] │
│ 1 │ 'someMethod' │ [ 'b?: String' ] │
│ 2 │ 'someMethod' │ [ 'aOrB?: ' ] │
│ 3 │ 'someOtherMethod' │ [] │
└─────────┴───────────────────┴───────────────────┘
from tst-reflect.
- yeah, thats wrong. Implementation shoud not be visible. Ctors are ok, methods are not.
- I just simply ouput type name. That union is
Container
type, it does not have name. There isType.isUnion()
andType.getTypes()
. The getTypes returns array of unioned types, you have to handle it.
from tst-reflect.
Still a bug for me until I fix that issue with listed implementation signature which. I think I'll be able to fix it today.
from tst-reflect.
I just published [email protected]
and [email protected]
with fixed method overloads and added function overloads.
from tst-reflect.
@all-contributors please add @carloszimm for ideas and bug report
from tst-reflect.
Got it.
Thanks, @Hookyns!
Looking forward to your fix :)
from tst-reflect.
@Hookyns
I tested and it's working as expected (following your output posted above). I just have some questions.
1 - While the output for the "someMethod" listed the definitions as well as the implementation, the output for the constructor only included the definitions of it. Is that the expected output?
2 - The last output of "someMethod" didn't show the (union) type for the parameter. Is that the expected output? If so, should I invoke a different method for union types for example?
from tst-reflect.
Gotcha (:
from tst-reflect.
- yeah, thats wrong. Implementation shoud not be visible. Ctors are ok, methods are not.
@Hookyns before closing this issue, should the above point still be flagged as a bug or it was a matter of modifying the code (solution) to detect those specific cases (methods)?
from tst-reflect.
Important to note that it's an overload matter. If there wasn't overload, the output of the implementation signature would be ok :)
from tst-reflect.
Sure 🙂
from tst-reflect.
Hello again @Hookyns
So, I'm facing trouble when it comes to reflect on functions + overloads. To be more specific, I'm trying to reflect on functions exported by a library, and many of them have overloads. Your above examples reflect on classes which is more straight forward but the functions (signatures + implementation) I'm working on are all exported separately using ES module (all located at the same file). I followed the code available in #48 but it only prints the first signature (overload) of the function and I have no idea how to modify it adequately to handle that case. For instance, supposing I'm trying to reflecting on the following function (filter) of the RxJS library (one of my fav libs); I can only get the first signature listed in that file using the code of #48. Any ideas on how to properly handle this case or it is something still to be implemented/enhanced in the tst-reflect lib? I thought about trying to gather those signatures in some way/object to then get the overloads' infos but I have no clue how to proceed.
Thanks!
from tst-reflect.
I've put up a pull request to add @carloszimm! 🎉
from tst-reflect.
Related Issues (20)
- Support decorators from TS 4.8 HOT 2
- Unable to access parameter decorators HOT 2
- [BUG] Set not comparable HOT 1
- [Question] Anyway to add it as angular transformer HOT 18
- [BUG] tst-reflect: You call getType() method directly. You have probably wrong configuration, because tst-reflect-transformer package should replace this call by the Type instance. HOT 8
- [BUG] type metadata HOT 6
- Can't get `getType<T>()` to work HOT 5
- Participation in the new version of the system HOT 52
- [BUG] Watch mode HOT 1
- Can't get function to work with create-react-app HOT 3
- [BUG] Uncaught ReferenceError: _ßr is not defined HOT 4
- [Question] npm package using tst-reflect cannot be imported HOT 1
- [BUG] Union properties are broken HOT 5
- [BUG] TS 4.9 - "[ERR] tst-reflect: You call getType() method directly..." error when following base usage examples. HOT 17
- [Question] Comparison of Array types HOT 9
- [Question] How to get field type inside a decorator HOT 2
- [Question] Vite support HOT 3
- [Question] Does this work with functions? HOT 2
- Is there a way to use it with nestjs [Question] HOT 1
- Generic Type at runTime HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tst-reflect.