Giter Site home page Giter Site logo

Comments (5)

Marsup avatar Marsup commented on June 15, 2024 1

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.

Sandy-Garrido avatar Sandy-Garrido commented on June 15, 2024

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.

Sandy-Garrido avatar Sandy-Garrido commented on June 15, 2024

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.

Marsup avatar Marsup commented on June 15, 2024

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.

Sandy-Garrido avatar Sandy-Garrido commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.