Skip to content

chore: clean up type tests#16804

Merged
AlessioGr merged 3 commits into
payloadcms:mainfrom
mrazauskas:clean-up-type-tests
Jun 3, 2026
Merged

chore: clean up type tests#16804
AlessioGr merged 3 commits into
payloadcms:mainfrom
mrazauskas:clean-up-type-tests

Conversation

@mrazauskas

Copy link
Copy Markdown
Contributor

What?

This PR removes unnecessary asType() helper and typeof in type tests.

Why?

An expression or a type can be passed to both sides of TSTyche assertions. The following are equivalent; the redundant syntax can be removed improving the readability.

- expect(asType<JoinQuery<'pages'>>()).type.toBe<never>()
+ expect<JoinQuery<'pages'>>().type.toBe<never>()
- expect<(typeof user)['collection']>().type.toBe<'users'>()
+ expect(user.collection).type.toBe<'users'>()

Signed-off-by: mrazauskas <tom@mrazauskas.de>
Comment thread test/types/types.spec.ts
Comment on lines -740 to +732
expect<GeneratedRichTextType>().type.toBeAssignableWith<typeof _result>()
expect(result).type.toBeAssignableTo<GeneratedRichTextType>()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I also swapped sides of assertion and used toBeAssignableTo(). So it reads exactly as the test title and type under test stays on the left.

@AlessioGr AlessioGr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@AlessioGr AlessioGr enabled auto-merge (squash) June 2, 2026 23:49
@AlessioGr AlessioGr merged commit 484ae41 into payloadcms:main Jun 3, 2026
322 of 326 checks passed
@mrazauskas mrazauskas deleted the clean-up-type-tests branch June 3, 2026 03:19
@mrazauskas

Copy link
Copy Markdown
Contributor Author

@AlessioGr Thanks from sponsoring! I am glad to see TSTyche is useful at @payloadcms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants