Giter VIP home page Giter VIP logo

Comments (8)

fatcerberus avatar fatcerberus commented on May 24, 2024 2

Quote from the other issue, emphasis mine:

Background: The control flow graph creator can't resolve the types of expressions (doing so would create a circular dependency between passes of the compiler), but does have some logic for detecting if (true) {. Basically, TS thinks if (value === null) { might not always execute, because during the construction of the control flow graph, it is not yet known that __TRUE__ is true.

That's a pretty fundamental design constraint, and I highly doubt anything has changed in that regard.

Then again, TS can do control flow for asserts T and never returns as long as there's an explicit type annotation on the function, so who knows...

from typescript.

whzx5byb avatar whzx5byb commented on May 24, 2024 1

@kungfooman I'm only a passerby so I can't tell. You have to wait for a TS team member to answer it.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on May 24, 2024 1

The lint rule has a lot of false positives, e.g.

const n = [1, 2];
if (n[4] !== undefined) { // <- thinks this is always true
  
}

from typescript.

whzx5byb avatar whzx5byb commented on May 24, 2024

Duplicate of #29323.

from typescript.

kungfooman avatar kungfooman commented on May 24, 2024

Thank you @whzx5byb, that issue is from 2019, is it still a design limitation? I want to use some advanced type programming which figures out true/false values and have unreachability detection of it.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on May 24, 2024

Everything is of course in-principle solvable, but there aren't a lot of cases where people intentionally write if (expr) where expr is a complex expression which statically provable to be true (and then need the corresponding code to change color).

from typescript.

kungfooman avatar kungfooman commented on May 24, 2024

@RyanCavanaugh I investigated type checks on ranges a bit through type programming doing arithmetic, e.g. a function could return a random number from 20 to 100. If later there is an condition which checks that this number is bigger than... lets say 200, it can only be false (and ideally be pointed out through dead-code detection).

You already planned range based type flow in another PR and I just wanted to see if it's possible already without any extra PR's. But this issue makes range based type checks not too helpful as-is.

OTOH it seems to already exist, but with an extra linting step: https://typescript-eslint.io/rules/no-unnecessary-condition/

from typescript.

typescript-bot avatar typescript-bot commented on May 24, 2024

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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.