5 ms·
The title says "JavaScript", but the file extension says ".ts". It doesn't look very Javascript to me. Can anyone clarify?
by TomVDB 7y ago
The title says "JavaScript", but the file extension says ".ts". It doesn't look very Javascript to me.
Can anyone clarify?
- malvosenior 7y agoIt's typescript.
- sabrehagen 7y agoThe source code is TypeScript, which once compiled produces JavaScript.
- ashtonbaker 7y agoIt's TypeScript! It is "a strict syntactical superset of JavaScript, and adds optional static typing to the language." [1], and compiles to standard JavaScript. [1] https://en.wikipedia.org/wiki/TypeScript https://en.wikipedia.org/wiki/TypeScript
- ludston 7y agoA more correct word for converting code from one programming language into another is "transpile".
- antisemiotic 7y agoIt's always "from one language to another", sometimes the destination is machine language. The output is generally not meant to be meant to be human-readable in any case. "Transpile" is an ugly and unnecessary word, please don't push it as "more correct".
- chrisseaton 7y agoIt's just a more specific word. You can say all words are unnecessary because you can express the same thing using more words.
- antisemiotic 7y ago"Transpilation" and "compilation" describe the exact same concept. From user's perspective, readable code is translated into runnable code. From theoretical perspective, code in a more complex language is translated into a less complex language while preserving semantics. From a compiler writer's perspective, it's a totem pole of compilers, with at least one middle-level language usually. Plenty of people use the term "compiles to JavaScript" to describe languages like TS or Elm. It's just some overly pedantic people insist on the term "transpile" when the target is also, in a completely unrelated way, used to write code directly by a significant number of contemporary programmers.
- nwienert 7y agoTranspile is a superset or compile just like typescript is a superset of JavaScript. Transpile implies translating but not into a less complex language but rather onto a similar runtime. So typescript is dynamic just like JavaScript, and they share much of their semantics. So transpile means compile but onto a similar runtime with similar runtime semantic behavior.
- antisemiotic 7y agoIn that case surely you'd agree that there are hardly any compilers in wide use these days - more often than not the first step of a modern compiler is translation into a similar but less expressive intermediate language. Or does it only count as "transpilation" if the intermediate representation is an already existing language, thus making the distincion purely based on the history of a language, not the implementation?
- chrisseaton 7y ago> "Transpilation" and "compilation" describe the exact same concept. No I think transpile implies compiling from one level of abstraction to another similar level of abstraction, which is quite different in theory and practice to compiling to a much lower level of abstraction. It's a useful word to have in your communication toolbox.
- brianzelip 7y ago> It's always "from one language to another“ Hmmm, sometimes it’s “from one version of a language to another version of the same language”. As is the case with Babel[0] and JavaScript. [0] https://babeljs.io/ https://babeljs.io/
- LordDragonfang 7y agoI mean, arguably ES6 and TS are as close or closer to being "the same language" than ES6 and Babel targets.
- nomel 7y agoI think it's worded in a way that's odd to developers that usually write code for multiple target languages. What you type is usually considered what it's implemented in, not what it's compiled/transpiled to. The later is the target language, which there may be many. This differentiation is required if you want to modify/read the code. You would almost certainly modify/read it in the language it was implemented in, and make it clear which language this is when sharing. Maybe "...implemented in TS, targeting JS" or at least something more obvious like "...implemented in JS using TS".
- jchw 7y agoIt’s TypeScript. You can strip the annotations and type definitions and it’s pure JS. TS is typically ran on JS runtimes, hence why people consider TS programs to also just be JS program. *not exactly, there’s a couple of features that map differently. But there's a 1:1 TS to JS conversion.
- XCSme 7y ago.ts comes from TypeScript, which is just JavaScript but with compile-time-checked types (and some other goodies) added on top. TS is really popular now, I don't think any sane dev would start a new project today in plain JS instead of TS.
- chrisco255 7y agoThat's huge hyperbole there. Plenty of projects are started in JS today. It's still wise to provide typings to your user base if you're publishing a library, whether or not you're using TS under the hood.
- arcticbull 7y agoI agree with parent that while people will still start JS projects today they'd probably be better off with TS.