Giter VIP home page Giter VIP logo

Comments (3)

RyanCavanaugh avatar RyanCavanaugh commented on May 2, 2024 2

The linked issue is about what the language service (i.e. tooltips) reports about the left operand's type, not whether or not there's an error when you use ++ on that. It's not a duplicate.

from typescript.

MartinJohns avatar MartinJohns commented on May 2, 2024

Sounds like a duplicate of #53303. edit: it's not.

from typescript.

snarbies avatar snarbies commented on May 2, 2024

This problem also affects this form: hhh["asd"] = hhh["asd"]++;

I'm confused as to why the linked issue is closed as "Working as intended". The expression hhh["asd"]++ decomposes to:

let temp = hhh["asd"];
temp++;
hhh["asd"] = temp;

Written out that way, TS correctly identifies that we are reading a possibly-undefined value and then applying the ++ operator to it, which is an error. How is it correct that the same check should be elided with compound assignment when it represents identical logic?

This is the explanation offered:

Since it's both a read and a write, why is one of the answers correct and the other not? They have equal standing.

What has equal standing? The order of operations is read, increment, write. It's not one or the other, it's those three, in that order.

Edit: I guess that explanation is with respect to the type of the compound assignment expression—whether the type is inferred from the read side (number | undefined) or the write side (number). The linked issue is regarding the type of the expression. This issue is more about the failure to flag incrementing undefined as an error.

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.