Giter Club home page Giter Club logo

Comments (5)

jcalz avatar jcalz commented on August 21, 2024 3

I certainly didn't mean that t => !isAnimal(t) should return t is Rock no matter what Something is, that would be bonkers. Yes, I'd expect Exclude<Something, Animal>, which in your example code was Rock.

from typescript.

jcalz avatar jcalz commented on August 21, 2024 1

This is independent of filter():

function positive(t: Something) {
  return isAnimal(t)
}
// function positive(t: Something): t is Animal

function negative(t: Something) { 
  return !isAnimal(t)
}
// function negative(t: Something): boolean

I'm surprised that #57465 didn't do this. Inside negative() it certainly seems that !isAnimal(t) narrows in the way we expect:

function negative(t: Something) {
  if (!isAnimal(t)) {
    ((t));
    //^? (parameter) t: Rock
  } else {
    ((t));
    //^? ^?(parameter) t: Animal
  }
  return !isAnimal(t)
}

from typescript.

Noriller avatar Noriller commented on August 21, 2024 1

Actually, it should be Exclude<Something, Animal> because in the case we add another one, we want all except the one we are filtering out.

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240624#code/C4TwDgpgBAggdgSwLYEMA2UC8UDeAoKKAIwCcIVgALALimBIFcIAaPAXwG489RIoAlAPYBjANZZcBYmQo0oAM3QBnFuy49w0GGgQQ4E-IVLkqtOAzRpWnbr2gBlQUghUEcAOYT4ydFAA+AiLiAdq6cOryDHDCwAiC+ghK3qhoABRKTi6Ubu60js6uHgCUtBkF2R5QibCIKZKEZMAMJPplWTkAdMayWJjY9ExcbNzC8UrAdBDjAIx5mYWe2IbSJnIDqsN4o3Djk+MATHPlOQZS3aYKyhvq27vAU8AAzEftlUtnMhfmltY3YxOuJQASSUAHlxNgANr3GbMPbAfZwmFPAC6HXkCDQ9xIqQmmAAfFUkrV0LiikUuAB6SmEWmEAB6AH4aj40JCUSN-nRssClAB1EjxRZQaEPaZIh6I+GPNEYrEQHF4wkAQkSyVJwHJVJpdIZzNS6owASEYn8sB0eiK7KgAFobYSlJRBBYACbEaCpE3Bc1hK0c7jUqAATSmcKBAHIkFAUAB3FBkKBAqBKBimihQVCiE4QAAeKCQYDQUw6QA

from typescript.

fatcerberus avatar fatcerberus commented on August 21, 2024

@jcalz I don't think there's anything #57465 could have done to help here. We don't have negated types so you can't say t is not Animal--not even explicitly.

from typescript.

jcalz avatar jcalz commented on August 21, 2024

But we don't need t is not Animal, only t is Rock.

from typescript.

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.