Hookyns / tst-reflect

Advanced TypeScript runtime reflection system
MIT License
341 stars 11 forks source link

Type is not a Type. But is a Function which returns Type when type is recursive #42

Closed ciricc closed 2 years ago

ciricc commented 2 years ago

I've tried this sample with recursive type. And i found that type is a function, not a Type. I have last version of tst-reflect and ts-node.

import { getType } from 'tst-reflect';

type Settings = {
  users: User[];
};

type User = {
  friends: User[];
};

console.log(
  getType<Settings>()
    .getProperties()[0]
    .type.getTypeArguments()[0]
    .getProperties()[0]
    .type.isObjectLike()) // isObjectLike() is not a function
Hookyns commented 2 years ago

Hello @ciricc, TY for the issue. This is a bug. I'll look into it.

Hookyns commented 2 years ago

Fixed.

Try new versions tst-reflect@0.7.5 & tst-reflect-transformer@0.9.10

ciricc commented 2 years ago

Hello, @Hookyns . Thank you for reply. I've tried new version but it seems like now last .type property is just undefined, not a function.

TypeError: Cannot read properties of undefined (reading 'isObjectLike')

      54 |     .type.getTypeArguments()[0]
      55 |     .getProperties()[0]
    > 56 |     .type.isObjectLike()) // isObjectLike() is not a function
Hookyns commented 2 years ago

Okay, I'll check it again; this must be something with the Array, cuz I wrote test with:

type Node = {
    left: Node;
    right: Node;
};

it didn't work too and now it works. I should try your example first, sorry.

Hookyns commented 2 years ago

@ciricc Fixed in tst-reflect@0.7.6

ciricc commented 2 years ago

@Hookyns Thank you very much! Now is working ok