-
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
"print" types to compare them + better error messages #27
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ok, I think this makes performance significantly worse, to the extent that a bunch of existing tests will now fail because of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This (draft, initially) pull request attempts to get the best of both worlds from #21 and #16
Fixes #17
Fixes #26
Fixes #5
What this does:
toBeIdenticalTo
to replacetoEqualTypeOf
, andtoExtend
to replacetoMatchTypeOf
. The differences:toExtend
checks fortypeof
in the generic typearg if you want it, but it was making it impossible (or at least very hard) to consistently have readable CLI error messageserrors.test.ts
(based on Improve CLI error messages #16) to explicitly track exactly what it looks like when assertions fail (since that's really the point of this library, more than the "happy path" that usage.test.ts covers.string
->'string'
,void
->'void'
,'foo'
->string: foo
), and then puts them into a kind of assertion message likeExpected: string, Actual: number
. So the CLI error message (or the one in the IDE/on hover) will be something like:view
andprops
helpers for debugging, to make it easy to get a copy-pasteable resolved type:7. Adds support for "augmented" functions like `(() => number) & {foo: string}`
CC @trevorade @papb
In case either of you would be interested in reviewing,
src/index.ts
has the implementation, butprint-type.test.ts
is a useful way to see what the quite-complicatedPrintProps
actually does.errors.test.ts
shows roughly what error messages would look like (at time of writing, some work still to do for the varioustoBeString()
type methods still.@papb this uses some of the naming you've been suggesting over the past couple of years (if I remember right!) #10. It also fixes the bug you found #5 caused by microsoft/TypeScript#50670
@trevorade I know some of the issues you've been seeking to fix are around perf. Do you have a good way to test if this is ok performance-wise? In terms of functionality it's where I'd like it to be - it's basically an alternative rewrite of
Equals
that doesn't require.simplified
/works as expected for{a: 1} & {b: 1}
vs{a: 1; b: 1}
. As far as I've found, the only limitation it has is that it has to bail out of recursive types likeinferface X { x: X }
(no fancy loop checking - after it gets 20 props deep it just says 👋 ). The compiler hits "type instantiation is excessively deep and potentially infinite" if you set to 25 instead of 20 - but interestingly, without bailing out at all, VSCode just stalls.Some potential follow-ons:
toBeIdenticalTo
configurable, so you can do stuff likeexpectTypeOf<{a: readonly string}>().ignoringReadonly.toBeIdenticalTo<{a: string}>()
or somethingexpectTypeOf<MyLogger>().toBeExtendedBy<typeof console>()
to make sure your interfaces are compatible with existing types. You could always doexpectTypeOf<typeof console>().toExtend<MyLogger>()
but that failing implies there's something wrong withconsole
rather thanMyLogger
. @papb you also requested something like this at some point, right?expectTypeOf<MyThing>().notToHaveAnys()
andexpectTypeOf<MyThing>().notToHaveNevers()
which would make sure that there are noany
ornever
properties, even deeply nested ones - would be quite easy to implement now, and the error could probably tell you exactly where the offendingany
/never
has crept in.Problems/this might not work because:
PrintProps<MouseEvent>
hits "type instantiation is excessively deep and possibly infinite".