-
Notifications
You must be signed in to change notification settings - Fork 188
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
test: ensure return type of functions #681
Comments
It would be nice if something like this worked. It does show an error in the editor and doesn't pass the script // idea for packages/dinero.js/src/api/__tests__/toSnapshot.test.ts in branch feat/to-units
describe('custom transformer', () => {
const amount = new Big(500);
const d = dinero({ amount, currency: bigjsUSD });
const expected = toSnapshot(d, ({ value }) => value.amount);
it('returns the expected value', () => {
expect(expected).toBe(amount);
});
it('returns the expected type', () => {
expect(() => {
// @ts-expect-no-error
const typed: Big = expected;
}).not.toThrow();
});
}); |
It's a good idea to add return types to functions. Initially I disabled it because I thought inference was better, but explicit return types ensure we don't accidentally break the API or that we don't have unexpected return types as in the example you shared. To do this, we need to:
|
Hi @sarahdayan am new to contributions, can I try to work on this ? |
There was an odd issue in PR #309, where a function returned
unknown
rather than the expected type but it didn't raise any type errors and passed all the tests.There must be a standard way to test types, and prevent this in the future.
The text was updated successfully, but these errors were encountered: