Comments (5)
It's more accurately representing reality. In case of error, it contains the best effort result of the validation, but it's certainly not an encouragement to use it.
What is it breaking exactly?
from joi.
Hmm, I see your case.
Though previously, it would represent the type correctly if you'd throw/return the error.
Following on from the example in my OP. Previously:
const {value, error} = schema.validate(someone)
// value: Person | undefined
if(error){
// throw/return
}
// value: Person
// we correctly would receive value as Person type only instead of before the throwing it could have been undefined
I feel like this is a pretty major change in that we're now just returning any here considering we just validated it. Now we just see any
regardless of whether we escape on error
from joi.
I think the bug essentially is that TSchema is never displayed because any
overpowers it
see this TSPlayground https://www.typescriptlang.org/play?#code/C4TwDgpgBAChBOBnA9gOygXigbwFBQKlQEMBbCALikWHgEtUBzAblwF8oAfKXPQospSjFUIVm1y4AxmhpRISNFTiL0WPoRLkqAIkQiAJiB3tJM1HP2ojmeQhSoAdFoi4A9G+qGQUOomGiQA
type Person = {
name: string;
} |
{
name: any;
}
const person: Person = {
name: "sandy"
}
const sandy = person.name
// sandy is always any
from joi.
It still works if you check the error https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKQsOAzKERwOQCtnYDcAUMTAJ5gCmcAClVAM4QB2cAvHAN7FxwCGAcyoAuOCwCuIAEYMSfFvxCi4jGFGAtBJAL6kAxqzWrMVVivpNWHbr3FKVAIkb8WAE3KOANHaEqATAAMxHrEhizGjPoAFlQg-DZIwAB0ENK4VPowADyWzCwAfAAUPAoOYknJahpaRQCUPnx+FcjJkjIM9SF1BkbwXABu-AA2ElRecAwYUDo2UbHxyUPDwG78MFRFzMrmdSSkwKhwRQCEU9B1tnx8y2PJfvLXt1T3wlRUusRAA. I guess the only other type that would make sense would be unknown
, but it wouldn't change your problem.
from joi.
Strange, It wasn't working the way I expected at first. Just tried it now and yes, it is working as expected and I agree with the undefined to any change. I thought there was a bug but seems at home it no longer is the case! So will close this now!
from joi.
Related Issues (20)
- Error.captureStackTrace(this, exports.assert); HOT 7
- Property 'min' does not exist on type 'StringSchema<string>'. HOT 2
- Domain validation not checking IANA registry by default HOT 1
- abortEarrly = false and formatting the return of multiple errors HOT 1
- joi.allow array HOT 2
- Optional is missing in definition file HOT 2
- Joi.ref format(value) function HOT 1
- joi not usable in a browser environment HOT 1
- Multiple uri validation HOT 2
- Need all type control messages HOT 3
- Must run on Joi instance HOT 2
- Custom message for required field HOT 3
- Are `{}@gmail.com` and `%@gmail.com` valid email addresses? HOT 2
- Add a script to run only specific test HOT 2
- Custom transformation of a value HOT 3
- Joi does not work with application with Custom Prototypes HOT 2
- Setting `errors.label` to `false` does not remove labels from error messages for keys with labels HOT 1
- The documentation doesn't explain overrides or re-using naming conventions of existing rules when extending joi
- Custom error context with references
- Typo in Joi Validation with Swagger... HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joi.