-
Notifications
You must be signed in to change notification settings - Fork 3
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
Its not good idea to extends Interfaces , classes with reflector functions #9
Comments
Actually the solution you proposed in your second snippet is totally feasible, since it's a class: reflect(MyTestClass).members.forEach( member=> console.log(member));
Instead, interfaces do not leave anything during emitting phase, so we must have something to handle their "references". We may use strings, but it's not so immediate, it's error prone and not refactor-friendly. What kind of issue you see about using |
Now , if we want to create any tool using typescript for reflection - we should to build it using your custom compiler. import * as React from 'react';
export class FirctComponent extends React.Component<{ member1: number }, {}>{
} So, i suggest somthing like this import {reflector} from 'ts-reflector';
reflector('../projects/MySuperProject/src/MyComponents.ts').classes.filter( cl => cl.base.name === 'ReactComponent').map(cl => ( cl.base.genericsParams[0]).forEach(propsInterface => {
propsInterface.members.forEach(member =>{
console.log(member.name);
console.log(member.comments);
});
}) should print |
Ok, now I got your point. I know that already exists some library that simply does mere type extraction from a typescript source. Actually this is not the scope of reflec-ts that instead aims to link classes (constructor functions) with their metadata seamlessly. I'll try to elaborate this concept better. Let's suppose you have a class somewhere hidden in your code and a factory instantiates an object of this class. You are building a DI framework that needs to know if that object's class implements a specific interface because it has to decide at runtime which object inject into another, using interfaces. Here, the only way to get Here, this is the point. Only a compiler can do this thing. Somewhere in the source code, in your super-private module, just after the Let me know if something is not clear, I realized that this is a very complex topic, so feel free to ask and open more issues if you need. I'm happy to contribute to the TypeScript community. P.S.: it should be not so difficult to use reflec-ts instead of the official TypeScript compiler: the API is the same, the |
I am interested in this project for the exact purpose of type extraction from interfaces for documentation purposes. I am not aware of any other tool that works with newer version of typescript. Which libraries are you referring to? |
You may want to try ts-type-info. |
Thanks, I'll check it out! |
Hello, thank you for this project.
Now we can write somthng like this
But i think it's not good;
Standard reflection framework just provide functions to reflect.
And we can just pass Class or Interface to function;
If your aim - jsut provide intellisence for usage reflector functions - we can create any type like Type in .Net reflection
I know tha we can't pass interface to function cause it's typescript syntax limitation;
What do you think about it?
The text was updated successfully, but these errors were encountered: