Giter VIP home page Giter VIP logo

Comments (6)

jpelton-stroud avatar jpelton-stroud commented on July 23, 2024 1

ah, apparently I fell prey to that "novice puzzlement" you mentioned :P Thank you for the clarification!

from typescript-handbook.

dwarburt avatar dwarburt commented on July 23, 2024

I came here because I couldn't find documentation for the switch statement in the handbook. It seems like there is a missing page for "expressions" that could cover typeof, switch and others.

from typescript-handbook.

estaub avatar estaub commented on July 23, 2024

@dwarburt AFAIK switch in Typescript is unmodified from Javascript. Is there something Typescript-specific you were looking for? The handbook doesn't cover most of vanilla Javascript, for obvious reasons. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch.

from typescript-handbook.

dwarburt avatar dwarburt commented on July 23, 2024

I was trying to find out if it's possible to switch on the type of a variable. It's not obvious to me that the handbook shouldn't cover all the parts of the language. It certainly covers a lot of vanilla JavaScript already.

At least it would be nice if it said somewhere that this particular language construct is unmodified.

from typescript-handbook.

jpelton-stroud avatar jpelton-stroud commented on July 23, 2024

The typeof operator, as used in type queries rather than Javascript, isn't documented

Like @estaub mentioned of switch, typeof is also a native JS operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

from typescript-handbook.

estaub avatar estaub commented on July 23, 2024

@jpelton-stroud Sorry, but I'm not sure what your point was. If you were saying that the MDN doc covers use of typeof in TS as a type query operator, you'd be wrong; static typing is a foreign concept to JS that can't even begin to be discussed in JS terms. I suppose I should provide an example, to be crystal clear:

    const JoeSchmoe = { name: 'Schmoe, Joe', district: '42' }
    type legislator = typeof JoeSchmoe  // == { name: string; district: string }

from typescript-handbook.

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.