Giter Site home page Giter Site logo

Comments (15)

Hookyns avatar Hookyns commented on June 1, 2024 2

@carloszimm
Implemented in [email protected] and [email protected].

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024 2

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.

Hookyns avatar Hookyns commented on June 1, 2024 1

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.

Hookyns avatar Hookyns commented on June 1, 2024 1
  • 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 is Type.isUnion() and Type.getTypes(). The getTypes returns array of unioned types, you have to handle it.

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024 1

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.

Hookyns avatar Hookyns commented on June 1, 2024 1

I just published [email protected] and [email protected] with fixed method overloads and added function overloads.

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024 1

@all-contributors please add @carloszimm for ideas and bug report

from tst-reflect.

carloszimm avatar carloszimm commented on June 1, 2024

Got it.
Thanks, @Hookyns!
Looking forward to your fix :)

from tst-reflect.

carloszimm avatar carloszimm commented on June 1, 2024

@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.

carloszimm avatar carloszimm commented on June 1, 2024

Gotcha (:

from tst-reflect.

carloszimm avatar carloszimm commented on June 1, 2024
  • 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.

carloszimm avatar carloszimm commented on June 1, 2024

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.

Hookyns avatar Hookyns commented on June 1, 2024

Sure 🙂

from tst-reflect.

carloszimm avatar carloszimm commented on June 1, 2024

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.

allcontributors avatar allcontributors commented on June 1, 2024

@Hookyns

I've put up a pull request to add @carloszimm! 🎉

from tst-reflect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.