test(types): use tstyche
instead of tsd
#1525
Draft
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.
What kind of change does this PR introduce?
This PR migrates type test to TSTyche. Similar to supabase/postgrest-js#633
/cc @avallete
What is the new behavior?
This repo has only one test file, so I took an opportunity to demo TSTyche specific features:
test()
helpers and assertions like.toBe()
,.not.toBeCallableWith()
.In the PR of
supabase/postgrest-js
repo, checks of// @ts-expect-error
are used. Which is a good idea, of course. Only that it makes testing agains many versions of TypeScript less smooth, because of changing message text.In a way the message text is only implementation detail. In this PR I used
.not.toBeCallableWith()
which tries to call the given expression and passes if there is any error. (It also checks if the expression is actually callable.) This way testing can be done across several TypeScript versions.By the way, the actual calling of the expression is implemented via erased syntax:
roughly becomes:
Additional context
Current version of
tsd
ships and uses TypeScript 5.3.3. TSTyche is using the installed version of TypeScript which currently is 4.7.4.As suggested in the above mentioned PR, in CI it would be possible to run tests agains a range of TypeScript versions:
tstyche --target '>=4.7'
. The exact range should be decided.Sorry, I can’t figure out how to update
deno.lock
.