question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get `getType<T>()` to work

See original GitHub issue

Hello! Awesome project. Thank you!

I have a question, not sure if I am hitting a setup bug, but I am using tst-reflect through webpack and ttypescipt. I have this snippet:

interface IFoo {}
class Foo implements IFoo {}

const foo = new Foo();
getType<Foo>();
getType<typeof foo>();
getType<IFoo>();

I can see my source is instrumented with reflection data correctly, but these calls are all compiling to empty getType() calls. Am I doing something wrong?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
3p3rcommented, Oct 25, 2022

Thanks so much for the detailed response. I also found https://ts-morph.com/ in the meantime that has worked with tst-reflect and doing in-memory compilation. Using ts-morph is admittedly less confusing than the original compiler API.

0reactions
Hookynscommented, Oct 25, 2022

@3p3r

I played with it a little…

The issue is in transpileModule inside typescript itself. It does not load declarations of modules etc. It only transpile given module. getType<>() calls were not recognized as our getType calls so we ignored them. Recognition is based on declaration.

I did some changes, so every getType<T>() without declaration (typechecker returns error for such function), called exactly with one type argument, will be considered as our. Here is new demo.

Included in tst-reflect-transformer@0.12.5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No TypeTag Available Exception when using case class to try ...
I finally found out what the issue was. The case classes must be defined top level - they cannot be nested. Something like...
Read more >
Problem calling string parse + eval from C++ - Julia Discourse
when called from C++ using jl_call, I cannot get the output of “println(a)", the problem came from eval in previous line.
Read more >
[Solved]-Get actual type of T in a generic List<T>-C#
I have an object which contains a List<T> for some type T . How do I retrieve the type T via reflection? Short...
Read more >
Visitors' Frequently Asked Questions | Getty Center
Admission · Is it free to visit? · How do I make reservations? · I didn't get/can't find the confirmation email about my...
Read more >
INF4140 - Models of concurrency - UiO
even on a single processor: use many processes, in order to get a natural partitioning ... Atomic operations on a variable cannot happen...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found