deepkit / deepkit-framework

A new full-featured and high-performance TypeScript framework
https://deepkit.io/
MIT License
3.14k stars 116 forks source link

[Bug] getter method not recognized #246

Open hanayashiki opened 2 years ago

hanayashiki commented 2 years ago

Hello, I really like the idea of this library! I hope it can go on and become mainstream of TypeScript server development.

Currently I have experienced with the follow bug (or missing feature)?

class Getter {
  get a(): number {
    return 1;
  }
}

console.log(typeOf<Getter>());
<ref *1> {
  kind: 20,
  classType: [class Getter] {
    __type: [ '!5', __unpack: [Object], __type: [Circular *1] ]
  },
  types: [ { kind: 0, parent: [Circular *1] } ],
  typeArguments: undefined
}

typeOf<Getter>() doesn't return anything about the get a(): number getter method, no matter I annotate the return type or not. Getter type can be really useful when we want to precompute something on the server and pass that to the client, but it seems deepkit doesn't recognize them.

Thank you!

marcj commented 2 years ago

That's currently not supported. Flagged as feature.

marcus-sa commented 2 years ago

Hello, I really like the idea of this library! I hope it can go on and become mainstream of TypeScript server development.

Currently I have experienced with the follow bug (or missing feature)?

class Getter {
  get a(): number {
    return 1;
  }
}

console.log(typeOf<Getter>());
<ref *1> {
  kind: 20,
  classType: [class Getter] {
    __type: [ '!5', __unpack: [Object], __type: [Circular *1] ]
  },
  types: [ { kind: 0, parent: [Circular *1] } ],
  typeArguments: undefined
}

typeOf<Getter>() doesn't return anything about the get a(): number getter method, no matter I annotate the return type or not. Getter type can be really useful when we want to precompute something on the server and pass that to the client, but it seems deepkit doesn't recognize them.

Thank you!

A workaround could possibly be implementing an interface that has the property defined, or extending an abstract class that has the abstract property defined.