typegoose / typegoose

Typegoose - Define Mongoose models using TypeScript classes.
https://typegoose.github.io/typegoose/
MIT License
2.21k stars 139 forks source link

Refactor `assertion` to take a function to construct a error instead of always constructing the error #641

Closed hasezoey closed 2 years ago

hasezoey commented 2 years ago

Versions

What is the Problem?

Currently, when calling assertion, the value in the second parameter, which should always be a error, gets constructed even when not "throwing" it, which can lead to weird error if the values are weird (see #638)

Code Example

class Test {
  constructor(...args) {
    console.log("Test triggered", ...args);
  }
}

assertion(true, new Test("hello");

output:

Test triggered hello

Do you know why it happens?

as explained above

See This Stackoverflow Question & Answer which explains it greatly, thought its for Rust, it still kinda applies to this problem at hand

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 9.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: