Comments (6)
ah, apparently I fell prey to that "novice puzzlement" you mentioned :P Thank you for the clarification!
from typescript-handbook.
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.
@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.
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.
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.
@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)
- `export =` also works with `import * as` HOT 1
- Typos in Enums and Type Inference
- awesome-typescript-loader is no longer maintained.
- Declaration example does not match documentation requirements HOT 1
- Documented applyMixins doesn't compile since TypeScript 2.7 HOT 1
- Samples code in "Metadata" section of "Decorators" page is wrong
- Exhaustiveness checking current state
- Misstatement in definition of `Partial<T>` HOT 1
- Typo on "Unions and Intersections" page HOT 2
- Please expand Type Checking JavaScript Files into mutiple sections HOT 1
- Broken link in the Compiler Options page HOT 1
- create project fail HOT 1
- in operator clarification
- Outdated information about circular references of type aliases
- Add an entry about "typesVersions" to the handbook HOT 1
- Typos in "Advanced Types"
- `this` is a keyword, not a variable
- Incorrect example on "Compiler Options" HOT 1
- Incorrect tree node definition in pages/Advanced Types.md
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript-handbook.