-
Notifications
You must be signed in to change notification settings - Fork 8
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
protect against any more #66
Conversation
This looks interesting. I checked out this branch quickly with: expectTypeOf<any>().toEqualTypeOf<{a: number}>() // not allowed
expectTypeOf<any>().toMatchTypeOf<{a: number}>() // not allowed
expectTypeOf<{a: any}>().toEqualTypeOf<{a: number}>() // fail
expectTypeOf<{a: any}>().toMatchTypeOf<{a: number}>() // pass !!!
expectTypeOf<any[]>().toEqualTypeOf<number[]>() // fail
expectTypeOf<any[]>().toMatchTypeOf<number[]>() // pass !!! Nested Please understand me right, I do admire all the effort which went into writing this library. My brain could hardly come up with something similar. All I can contribute are these tests for edge cases. No ideas how to handle these |
Yes, this looking for nested I have thought about adding an assertion like this, which might be a useful "did I do anything stupid, anywhere" check: const myValue = {
deeply: {
nested: {
property: {
value: JSON.parse('{}'), // whoops, this is an any
},
},
},
}
expectTypeOf(myValue).notToHaveAnyAnys() Which would fail with some helpful error containing a message along the lines of
Thank you - it's helpful! |
@mmkal This is good, however I think this should probably be opt in, and since it's checking nested fields, TypeScript might not be able to handle it well especially on lower versions. Here is an idea, we can implement this to sort of mirror |
Having let this sit for a while, I'm inclined to not do it. Esp since the feedback is "don't do this, it's inconsistent" or "make it opt in, it's inconsistent". I'd like to avoid too many different ways to do things, so I think we should just accept that Maybe for a future major version (v2 or beyond). |
@aryaemami59 @mrazauskas
Proposal for protecting against any in a fairly simple way. This might break some people's tests, but I imagine 99% are in cases where an
any
has unexpectedly snuck in.Related: this comment