-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat(typeQuery): add support for typeof of an imported module #128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with this, just concern about declaration index access. Are you sure there are now ways to have multiple declarations in these scenarios? :)
When do you think an imported symbol could have multiple declarations? I have to be honest I don't remember the case |
@uittorio I've changed the code slightly to fix a problem where a variable with inferred type of the module didn't work. To be clear, this is the case: import * as STAR from './module';
const moduleVariable = STAR;
createMock<typeof moduleVariable>(); I've reorganised the code a bit, I think now it makes more sense. Let me know about the multiple declarations (comment above). |
multiple declaration exists when you declare a variableDeclaration and an interfaceDeclaration with the same name
Or when you declare multiple declaration of the same interface
The declaration[0] in the second scenario is smart enough to get all the properties even if it doesn't look like it contains them. I just had an issue in the past that for some reason there was a variable declaration on top and I couldn't find the right declaration. |
@uittorio those cases work fine for the same reason: I'm getting the declaration and then I'm sending it again to do the process cycle (a.k.a. GetDescriptor) where, if needed, it will gets all the declarations. |
This PR adds support to cases like this:
It takes in account multiple exports, export default (with ad hoc code) and export equals.
I've also:
typeof Enum
was breaking the original Enumtypeof obj.method
Please Note: the mock of a module will contain everything that is exported, even interfaces and types that are not available to use.