Skip to content
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

Typescript testing #15017

Closed
2 tasks done
richardsimko opened this issue Nov 2, 2024 · 4 comments
Closed
2 tasks done

Typescript testing #15017

richardsimko opened this issue Nov 2, 2024 · 4 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class typescript Types or Types-test related issue / Pull Request

Comments

@richardsimko
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

This is a request to improve the testing of TypeScript types. In the last year our team has experienced multiple issues where breaking type changes have been shipped as part of patch or minor versions, all of which involve very basic use cases and are issues which I personally would think should be caught by CI.

Motivation

Fewer accidental breaking changes

Example

Here are a few examples of issues that I mean:

#14026
#14062
#14282
#14974

Since most issues are resolved rapidly there might be more which our team hasn't encountered as they have been fixed by the time we try to upgrade.

@richardsimko richardsimko added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class labels Nov 2, 2024
@richardsimko
Copy link
Author

I'm happy to help out with this but since I'm not familiar with the project I'd need some pointers on how it could/should be set up.

@hasezoey
Copy link
Collaborator

hasezoey commented Nov 3, 2024

Mongoose typescript tests are in test/types, try to find a test file which is related to your case and put it in a function with the github issue (if there is one) or a proper function name.
(personally i would prefer a more descriptive function name, or at least a comment explaining what it tests)

For cases which "should just work" not much more modification that a reproduction case is necessary, but if you want to be more exact use the helper types expectType, expectAssignable and expectError. (as for how to use them, i recommend to look at existing tests)

And to run those tests run npm run test-tsd locally.

Also typescript types are quite complicated and big and somewhat restrictive whereas mongoose (at runtime) allows a wide variety of ways it could be interacted with, so it is likely not possible to catch all issues.

From my experience, types in mongoose are "second class" and could be changed in any version, though it felt like that since 7.x it had become more stabilized (at least in terms of breakage in patch versions).

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Nov 3, 2024
@richardsimko
Copy link
Author

Thanks for the guidance, I'll make sure to check that out and add some additional test cases!

@vkarpov15
Copy link
Collaborator

I'm sorry you've experienced issues with our TypeScript types. You're always welcome to contribute test cases as @hasezoey described to help us make sure we don't break patterns that you rely on.

As a general rule of thumb, when we fix a bug we add a test, so you'll see that we added TypeScript tests to cover #1402 and #14282.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants