Skip to content
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

Generic Type at runTime #92

Open
LotfiAghel opened this issue Dec 10, 2023 · 1 comment
Open

Generic Type at runTime #92

LotfiAghel opened this issue Dec 10, 2023 · 1 comment
Labels
bug Something isn't working enhancement New feature or request

Comments

@LotfiAghel
Copy link

Describe the bug
the variable with type of generic Type doesn't work

The code causing the problem


interface IFoo<T> {}
class Foo<T> implements IFoo<T> {}

const foo = new Foo<number>();
console.log(getType(foo).name);//doesn't work and print "unknown" but should print "Foo" or something similar with c#

To Reproduce
Steps to reproduce the behavior:

  1. Build,
  2. run,
  3. see error...

Expected behavior
getType should return Type of variable with isGenericType==true and generic args [number]

@LotfiAghel LotfiAghel added bug Something isn't working enhancement New feature or request labels Dec 10, 2023
@Hookyns
Copy link
Owner

Hookyns commented Dec 12, 2023

Hello,
tst-reflect version 0.x is deprecated; it has quite a lot of issues.

I did a huge refactor, 1.0-alpha which is a lot better, but for some reason your example does not work with the runtime getType(var) call. It works with the static getType<Foo<number>>() call.
Here is an example with the alpha version: https://stackblitz.com/edit/rttist-playground-2ee7rk?file=src%2Findex.ts
It should be possible to fix it.

Here is an example with the latest version (WIP) based on completely new system. (This example is using esbuild!)
https://stackblitz.com/edit/rttist-playground-esbuild-with-plugin-sxzz4s?file=src%2Findex.ts
In this example it is working but the part working with generic types is WIP. It will log the base generic type definition, not the generic types "inherited" from the definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants