-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chore(deps): update dependency expect-type to v1 #9724
Merged
Merged
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
gitKrystan
pushed a commit
that referenced
this pull request
Mar 8, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
gitKrystan
pushed a commit
that referenced
this pull request
Mar 9, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
gitKrystan
added a commit
that referenced
this pull request
Mar 10, 2025
* Add perf info for re-materialization (#9681) * feat: runtime logging activation (#9683) * feat: runtime logging activation * fix bugs * more fixes * fix lint * fix build * fix more lint * nicer names * Fix bug where race condition causes errors during Request refresh (#9685) * Fix bug where race condition causes errors during Request refresh * Fix lint * Lint * feat(cache): add peekRemoteState to cache to view remote state (#9624) * feat(cache): add peekRemoteState to cache to view remote state * fix lint * update comment * commit working state * Add test for getRemoteRelationship * lint fixes * another change to expected docs * prettier fix * Test fixes * feat: add patchRecord util to JSON:API (#9687) * feat: immutable records should show only remote state, make builder types more useful (#9686) * chore: add more tests around edit workflows, make builder types more useful * implement immutable-shows-only-remote-state * fix lint * Fix: support all known http methods (#9689) * fix: support all known http methods * fix: support all known http methods * chore: fixup SchemaRecord readme (#9690) * chore: minor docs fixes * Feat: hasMany linksMode (#9676) * Port ManyArray class from the model package into the store package * Improve the MinimumManager type definition * Relax the json-api validation for hasMany relationships in linksMode * Adds schema record hasMany relationships in sync linksMode * Adds ManyArrayManager to manage hasMany relationship arrays * Adds mutate method to RecordArrayManager * Set the new ManyArrayManager to newly created ManyArrays * Fix hasMany read tests * Adds reloadHasMany method to ManyArrayManager * Adds mutate method to ManyArrayManager * Adds reference stability tests for sync hasMany relationships * Adds reordering hasMany relationship content test * Adds hasMany relationship reload test * Adds hasMany relationship reload tests * General fixes on hasMany tests * Improve logging on JsonApi cache * Update the parent record on a findHasMany operation * cleanup logging and types * fix types a different way * smarter still * fix lint --------- Co-authored-by: Chris Thoburn <runspired@users.noreply.github.com> * fix: make serialize utils smarter (#9692) * fix: make serialize utils smarter * fix lint * chore: add env vars to turbo config (#9693) * docs: small cleanup for SchemaRecord intro (#9694) * feat: SchemaRecord guide * cleanup schema-record * chore: [BREAKING to prior alpha/betas] prepare SchemaRecord for stable, lockdown exports (#9697) * chore: prepare SchemaRecord for stable, lockdown exports * cleanup imports * fix assertion * doc: link to jsonapi.org when referencing * doc: cleanup wording in SchemaRecord README * fix: Don't notify changes for attributes not registered with the schema (#9698) * internal: fixup diagnostic reporting (#9704) * internal: fixup diagnostic reporting * fix exit code * chore: update to pnpm 10 (#9699) * chore: update to pnpm 10 * fix prettier * fixup settings * fixup npmrc * fix lockfile * bump to 10.5.2 * make work with pnpm * add script to warp-drive package * fix patch * fixup no-shadow-rule * chore: fix fastboot test app * fix lock * chore: make diagnostic shutdown safer, use bun for holodeck server (#9705) * refactor diagnostic for safer teardown * make holodeck cleanup appropriately * fix request test and improve diagnostic a little bit * fix more tests * cleanup config * cleanup dependencies for fastboot scenario * fix types * fixup more tests * fixup more tests * dont launch holodeck for main test app (yet) * ensure less noise in CI * some improvements * a new approach * attempt no sync * use internal sync * more cleanup * fix sync * fix install * fix more missing peers * more vite cleanup * fix more tests, make diagnostic easier to launch * disable caching * try something * fix no-cache * fix missing testem * try fastboot again * cleanup * cleanup * try * updated lockfile with new npmrc settings * fixup comment * fixup fastboot * fix prod tests * restore settings * fix deprecation test * make nicer? * keep some changes * fix it * fix newline * dont use turbo * fixup more commands? * maybe * fixup * still use exec * fix scneario * update npmrc text * fix quote mark * fix(deps): update dependency vite to ^5.4.14 (#9666) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency globby to ^14.1.0 (#9708) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency bun-types to v1.2.4 (#9706) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency inflection to ~3.0.2 (#9664) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency terser-webpack-plugin to ^5.3.12 (#9710) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update node.js to >= 18.20.7 (#9711) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency globals to ^15.15.0 (#9715) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency rollup to ^4.34.9 (#9716) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency semver to ^7.7.1 (#9717) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update ember-core (#9719) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency debug to ^4.4.0 (#9714) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency @ember/optional-features to ^2.2.0 (#9713) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update asset-compilation (#9712) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @ember/string to v4.0.1 (#9721) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency command-line-args to v6 (#9722) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency expect-type to v1 (#9724) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency ember-inflector to v5 (#9723) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency mocha to v11 (#9726) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency rimraf to v6 (#9727) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update oven-sh/setup-bun action to v2 (#9729) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency ember-cli to v6 (#9733) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update build-tools (#9570) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency ember-load-initializers to v3 (#9736) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency globals to v16 (#9737) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Fix metric count data typo * fix(deps): update code-quality (#9571) * fix(deps): update code-quality * dont bump @types/qunit --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris Thoburn <runspired@users.noreply.github.com> * bump version of tracerbench * chore: add logging to proxy server for debugging * chore: Modernize Performance App (use Vite) (#9707) * stash * stash * cleanup lockfile * more updates to harness * more work on scenarios * add bun log * simplify perf test build * another pass through * turns out we want compat * make easier to debug * turn on verbose logging * try * use string :eyeroll: * exclude more logs * exclude more * add debug mode for chrome * give longer timeout for logging * lets inspect * fix server * update check, reduce logging * fckn finly * chore: update main version of perf checks * chore: fixup vite config for perf (#9744) fixup vite config for perf * feat: new perf scenario for complex records (#9745) * chore: update scenario * chore: remove mixin workaround * More dramatic update for update-with-same-state perf test (#9743) * More dramatic update * Iterate parent of each child * Add big many to many scenario * Tidy up * Enbiggen * chore: bump size of benchmark (#9746) * Actually add the m2m test case to the perf test output (#9748) * Actually add the m2m test case to the perf test output * Update .github/workflows/perf-check.yml --------- Co-authored-by: Chris Thoburn <runspired@users.noreply.github.com> * chore: update perf suite (#9749) * Don't overnotify for updates to added state that match local updates (#9702) * Don't overnotify for updates to added state that match local updates * Fix typo * Tidy up * stash stuffs * Add log counts to replace-related-records * update all the stuffs * fixup log --------- Co-authored-by: Chris Thoburn <runspired@users.noreply.github.com> * Backport tests/main/tsconfig * Remove unneccessary test assertions --------- Co-authored-by: Chris Thoburn <runspired@users.noreply.github.com> Co-authored-by: Rich Glazerman <rglazerman@squareup.com> Co-authored-by: Leo Euclides <leoeuclidss@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
MehulKChaudhari
pushed a commit
to MehulKChaudhari/ember-data
that referenced
this pull request
Mar 16, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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 PR contains the following updates:
^0.20.0
->^1.2.0
Release Notes
mmkal/expect-type (expect-type)
v1.2.0
Compare Source
What's Changed
❗
toMatchTypeOf
is now deprecated. There are no plans to remove it any time soon, so it's not critical to immediately remove usages, but if you want to avoid squigglies in IDEs complaining about deprecations, here's what you should do:If you have an assertion like this:
There are a few options for upgrading it. The easiest is
toExtend
which is identical to the behaviour oftoMatchTypeOf
:This will work in all cases. But, there is now a stricter option that will work in many cases and be slightly more likely to catch things like
readonly
properties matching:But, as the name suggests, this will only work on plain object types, it will fail for union types, and some other complex types.
If you have code like this:
You'll need to use
typeof
becausetoExtend
andtoMatchObjectType
do not accept argumentsFull Changelog: mmkal/expect-type@v1.1.0...v1.2.0
v1.1.0
Compare Source
What's Changed
.toBeBigInt()
by @aryaemami59 in https://github.com/mmkal/expect-type/pull/123Full Changelog: mmkal/expect-type@v1.0.0...v1.1.0
v1.0.0
Compare Source
v1! 🎉🎉🎉
After many years being commitment-phobic, expect-type is now in v1.
This release does not add any user facing features on top of v0.20.0 or v1.0.0-rc.0. It's just "making it official". For anyone new to the project, or coming here from vitest or viteconf (👋 ), the usage docs from the readme are pasted below.
For anyone on an old-ish v0 version, here are links to the non-trivial changes that have gone in since v0.15.0:
.pick
and.omit
thanks to @aryaemami59.branded
helper for the old behaviour. Also support functionthis
parameters - thank to @trevorade and @papbFull usage docs below, for newbies (head to the readme to keep up to date):
docs from readme
Installation and usage
Documentation
The
expectTypeOf
method takes a single argument or a generic type parameter. Neither it nor the functions chained off its return value have any meaningful runtime behaviour. The assertions you write will be compile-time errors if they don't hold true.Features
Check an object's type with
.toEqualTypeOf
:.toEqualTypeOf
can check that two concrete objects have equivalent types (note: when these assertions fail, the error messages can be less informative vs the generic type argument syntax above - see error messages docs):.toEqualTypeOf
succeeds for objects with different values, but the same type:.toEqualTypeOf
fails on excess properties:To allow for extra properties, use
.toMatchTypeOf
. This is roughly equivalent to anextends
constraint in a function type argument.:.toEqualTypeOf
and.toMatchTypeOf
both fail on missing properties:Another example of the difference between
.toMatchTypeOf
and.toEqualTypeOf
, using generics..toMatchTypeOf
can be used for "is-a" relationships:Assertions can be inverted with
.not
:.not
can be easier than relying on// @​ts-expect-error
:Catch any/unknown/never types:
.toEqualTypeOf
distinguishes between deeply-nestedany
andunknown
properties:You can test for basic JavaScript types:
.toBe...
methods allow for types that extend the expected type:.toBe...
methods protect againstany
:Nullable types:
More
.not
examples:Detect assignability of unioned types:
Use
.extract
and.exclude
to narrow down complex union types:.extract
and.exclude
return never if no types remain after exclusion:Use
.pick
to pick a set of properties from an object:Use
.omit
to remove a set of properties from an object:Make assertions about object properties:
.toEqualTypeOf
can be used to distinguish between functions:But often it's preferable to use
.parameters
or.returns
for more specific function assertions:Up to ten overloads will produce union types for
.parameters
and.returns
:Note that these aren't exactly like TypeScript's built-in Parameters<...> and ReturnType<...>:
The TypeScript builtins simply choose a single overload (see the Overloaded functions section for more information)
More examples of ways to work with functions - parameters using
.parameter(n)
or.parameters
, and return values using.returns
:.toBeCallableWith
allows for overloads. You can also use it to narrow down the return type for given input parameters.:.toBeCallableWith
returns a type that can be used to narrow down the return type for given input parameters.:.toBeCallableWith
can be used to narrow down the parameters of a function:You can't use
.toBeCallableWith
with.not
- you need to use ts-expect-error::You can also check type guards & type assertions:
Assert on constructor parameters:
Constructor overloads:
Check function
this
parameters:Distinguish between functions with different
this
parameters:Class instance types:
Promise resolution types can be checked with
.resolves
:Array items can be checked with
.items
:You can also compare arrays directly:
Check that functions never return:
Generics can be used rather than references:
Distinguish between missing/null/optional properties:
Detect the difference between regular and
readonly
properties:Distinguish between classes with different constructors:
Known limitation: Intersection types can cause issues with
toEqualTypeOf
:To workaround for simple cases, you can use a mapped type:
But this won't work if the nesting is deeper in the type. For these situations, you can use the
.branded
helper. Note that this comes at a performance cost, and can cause the compiler to 'give up' if used with excessively deep types, so use sparingly. This helper is under.branded
because it deeply transforms the Actual and Expected types into a pseudo-AST:Be careful with
.branded
for very deep or complex types, though. If possible you should find a way to simplify your test to avoid needing to use it:So, if you have an extremely deep type that ALSO has an intersection in it, you're out of luck and this library won't be able to test your type properly:
Another limitation: passing
this
references toexpectTypeOf
results in errors.:Overloads limitation for TypeScript <5.3: Due to a TypeScript bug fixed in 5.3, overloaded functions which include an overload resembling
(...args: unknown[]) => unknown
will excludeunknown[]
from.parameters
and excludeunknown
from.returns
:This overload, however, allows any input and returns an unknown output anyway, so it's not very useful. If you are worried about this for some reason, you'll have to update TypeScript to 5.3+.
Why is my assertion failing?
For complex types, an assertion might fail when it should if the
Actual
type contains a deeply-nested intersection type but theExpected
doesn't. In these cases you can use.branded
as described above:Where is
.toExtend
?A few people have asked for a method like
toExtend
- this is essentially whattoMatchTypeOf
is. There are some cases where it doesn't precisely match theextends
operator in TypeScript, but for most practical use cases, you can think of this as the same thing.Internal type helpers
🚧 This library also exports some helper types for performing boolean operations on types, checking extension/equality in various ways, branding types, and checking for various special types like
never
,any
,unknown
. Use at your own risk! Nothing is stopping you from using these beyond this warning:For a dedicated internal type library, feel free to look at the source code for inspiration - or better, use a library like type-fest.
Error messages
When types don't match,
.toEqualTypeOf
and.toMatchTypeOf
use a special helper type to produce error messages that are as actionable as possible. But there's a bit of a nuance to understanding them. Since the assertions are written "fluently", the failure should be on the "expected" type, not the "actual" type (expect<Actual>().toEqualTypeOf<Expected>()
). This means that type errors can be a little confusing - so this library produces aMismatchInfo
type to try to make explicit what the expectation is. For example:Is an assertion that will fail, since
{a: 1}
has type{a: number}
and not{a: string}
. The error message in this case will read something like this:Note that the type constraint reported is a human-readable messaging specifying both the "expected" and "actual" types. Rather than taking the sentence
Types of property 'a' are incompatible // Type 'string' is not assignable to type "Expected: string, Actual: number"
literally - just look at the property name ('a'
) and the message:Expected: string, Actual: number
. This will tell you what's wrong, in most cases. Extremely complex types will, of course, be more effort to debug, and may require some experimentation. Please raise an issue if the error messages are misleading.The
toBe...
methods (liketoBeString
,toBeNumber
,toBeVoid
, etc.) fail by resolving to a non-callable type when theActual
type under test doesn't match up. For example, the failure for an assertion likeexpectTypeOf(1).toBeString()
will look something like this:The
This expression is not callable
part isn't all that helpful - the meaningful error is the next line,Type 'ExpectString<number> has no call signatures
. This essentially means you passed a number but asserted it should be a string.If TypeScript added support for "throw" types these error messages could be improved. Until then they will take a certain amount of squinting.
Concrete "expected" objects vs type arguments
Error messages for an assertion like this:
Will be less helpful than for an assertion like this:
This is because the TypeScript compiler needs to infer the type argument for the
.toEqualTypeOf({a: ''})
style and this library can only mark it as a failure by comparing it against a genericMismatch
type. So, where possible, use a type argument rather than a concrete type for.toEqualTypeOf
andtoMatchTypeOf
. If it's much more convenient to compare two concrete types, you can usetypeof
:Overloaded functions
Due to a TypeScript design limitation, the native TypeScript
Parameters<...>
andReturnType<...>
helpers only return types from one variant of an overloaded function. This limitation doesn't apply to expect-type, since it is not used to author TypeScript code, only to assert on existing types. So, we use a workaround for this TypeScript behaviour to assert on all overloads as a union (actually, not necessarily all - we cap out at 10 overloads).Within test frameworks
Vitest
expectTypeOf
is built in to vitest, so you can importexpectTypeOf
from the vitest library directly if you prefer. Note that there is no set release cadence, at time of writing, so vitest may not always be using the very latest version.Limitations
A summary of some of the limitations of this library. Some of these are documented more fully elsewhere.
.brand
in these cases - and accept the performance hit that it comes with.toBeCallableWith
will likely fail if you try to use it with a generic function or an overload. See this issue for an example and how to work around it..parameter
and.parameters
helpers. This matches how the built-in TypeScript helperParameters<...>
works. This may be improved in the future though (see related issue).expectTypeOf(this).toEqualTypeOf(this)
inside class methods does not work.Similar projects
Other projects with similar goals:
tsd
is a CLI that runs the TypeScript type checker over assertionsts-expect
exports several generic helper types to perform type assertionsdtslint
does type checks via comment directives and tslinttype-plus
comes with various type and runtime TypeScript assertionsstatic-type-assert
type assertion functionsComparison
The key differences in this project are:
actual
andexpected
clear. This is helpful with complex types and assertions.expectTypeOf(...).not
any
(as well asunknown
andnever
) (see issues outstanding at time of writing in tsd for never and any).not
, to protect against functions returning too-permissive types. For example,const parseFile = (filename: string) => JSON.parse(readFileSync(filename).toString())
returnsany
, which could lead to errors. After giving it a proper return-type, you can add a test for this withexpect(parseFile).returns.not.toBeAny()
expectTypeOf(square).toMatchTypeOf<Shape>()
tsc
.Thanks to everyone who has helped with this over the years!
Full Changelog: mmkal/expect-type@v0.20.0...v1.0.0
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.