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
fix(jest): fix for incorrect typing of SpyObject for Jest #96
Conversation
Build is now stable. |
It might be a breaking change because maybe there are people that from some reason are still in < 2.8. |
Strictly speaking yes. I checked it on our project, but this change seems to be perfectly backwards compatible with Jest 23.x. The reason is that it was already wrong since the beginning of the Jest support in Spectator, but Jest 24 has a lot of TypeScript improvements and on Jest 23.x one would not get any errors from it. |
Oh, sorry. You meant Typescript < 2.8. Angular 6 depends on TypeScript 2.7 Can we drop support for Angular 6 and introduce a new (major?) version of Spectator? Alternative would be: just |
Yes, and you could also upgrade to Jest 24? |
Yes, but this fix is required for Jest 24. ;) Otherwise you get compile errors. |
Sure |
@NetanelBasal what fix would you suggest for now? |
I'm suggesting to release a new major version and update both Jest and Typescript. |
Just simplified it a bit and added Typescript 2.8 as peer dependency. |
Does this require a major release? |
I ‘m not sure. Spectator API itself hasn’t changed, but its peer dependencies have. Strictly speaking, it should. I know Angular does TS upgrades for major versions as well. See also semver/semver#148. It’s up to you to decide. ;) |
I'm not sure if someone is still using Angular 6 🤔. I don't think it's worth a new major version. |
3.6.0 |
Just upgraded to Jest 24, and got compiler errors. I think the reason this bug was nog blocking before, is that
@types/jest@24.0.0
is more strict with generics.The issue
Given an interface:
when you define
SpyObject<Person>
as{ [P in keyof Person]: Person[P] & jest.Mock<Person>
, thenpersonSpyObject.saySomething
would be a() => string & jest.Mock<Person>
. That is wrong, because it should be ajest.Mock<string>
.To get the return type of
Person[P]
I useReturnType
combined with conditional types from Typescript 2.8. Awesome stuff by the way.