9 ms·
Static TypeScript: A Static Compiler for the TypeScript Language
- pininja 7y agoAre there any plans to release this?
- AntiRush 7y agoIt already is. From the parent link: https://github.com/microsoft/pxt/ https://github.com/microsoft/pxt/
- abchatra 7y agoAlready part of Microsoft MakeCode learn to code ecosystem. Read this blog for more details: https://www.microsoft.com/en-us/research/blog/rocket-fast-embedded-typescript-for-makecode-arcade/?ocid=msr_blog_makearcd_tw https://www.microsoft.com/en-us/research/blog/rocket-fast-em...
- buu700 7y agoGiven that they're both TypeScript subsets with similar goals, how close is STS to AssemblyScript? And is WebAssembly also a planned or possible compilation target of STS?
- darzu 7y agoThere are no goals to target WebAssembly right now. STS is currently targeted towards MCUs, which makes it more comparable to uPython or AVR than AssemblyScript.
- ridiculous_fish 7y agoThis language is quite striking! TypeScript is a superset of JS but here we're going from the other direction. Make a language that is only the TypeScript extensions to JS, and drop all the JS parts. No Object (!!), no Date, TypedArray, RegExp, almost all the mainstays are gone. It's Java 1.0: static offsets and vtables. This feels like the beginning of TypeScript throwing its weight around. It has the momentum to supplant JS and this is an exploratory compatibility-breaking step.
- mschuetz 7y agoWhat's wrong with TypedArray? It provides kickass performance for things like graphics. Any replacement would have to be at least as fast.
- darzu 7y agoNothing is wrong with TypedArray. This might be added in the future. Currently it hasn't been necessary for the use cases STS is going for (educational programming for MCUs).
- tiborsaas 7y agoIt seems JS is not your favourite language :) There's already a solid technology in place to supplant it which is WebAssembly.
- vijaybritto 7y agoThe only reason typescript has gotten the massive adoption is because its a superset of JS. If you remove the js part then it wont grow anymore!
- pjmlp 7y agoIt worked pretty well for C++.
- vijaybritto 7y agowould it work in 2019 though?
- pjmlp 7y agoAssuming the same support as it got from OS vendors and third party C compiler vendors in the early 90's, surely.
- dangerbird2 7y agoIt seems like the main market for the language is education, specifically a high-level language for ARM-based arduino-compatibles, but with an SDK that can be hosted on a browser for easy distribution on school computers. Microsoft can use the nuts and bolts of their existing typescript compiler, which happens to be able to run in a browser, to implement the language.
- syrusakbary 7y agoI believe this will have major implications for the WebAssembly ecosystem. It also makes me wonder how AssemblyScript will fit into the picture. Anyone from Microsoft/TypeScript can shed some light on future plans?
- jedisct1 7y agoIn its current state, Static TypeScript is a toy compared to AssemblyScript. It doesn’t support much of the original TypeScript features, while AssemblyScript is getting pretty close to the original TypeScript. AssemblyScript was also specifically designed to target WebAssembly. For example, it supports 64 bit types and has builtins that directly map to WebAssembly opcodes. Static TypeScript would have to be repurposed as explicitly targeting WebAssembly in order to become a viable alternative. And Static TypeScript is part of a set of projects with very different goals. That being said, it could indeed be turned into something targeting WebAssembly. And unless Microsoft goes that route, it may happen as a fork. Still, I’m not sure of the benefits compared to AssemblyScript. I’d rather see Microsoft contribute to AssemblyScript.
- syrusakbary 7y agoSame. I’d like to analyze more time into the project, it seems is mainly for education proposes? Either way, I hope Microsoft pushes AssemblyScript forward :)
- darzu 7y agoLike you said, STS and AssemblyScript have very different goals. In fact, STS is generally not faster than vanilla JS on V8. STS is primarily targeted at MCUs which need a low space and memory footprint while still being reasonably performant. The main use case for STS is https://makecode.com https://makecode.com which is a CS EDU platform for physical computing.
- dangerbird2 7y agoAssemblyscript targets webassembly, while Static Typescript is designed for ARM microcontrollers. The main sell for static typescript seems to be that it provides a compiler, linker, and SDK for arduino-alikes that can be hosted on a client-side webapp for easy cross-platform distribution
- Can_K 7y agoSee it in action: https://arcade.makecode.com/85409-23773-98992-33605 https://arcade.makecode.com/85409-23773-98992-33605
- cztomsik 7y agoHere's another one (more mature, I'd say) https://github.com/AssemblyScript/assemblyscript https://github.com/AssemblyScript/assemblyscript
- craftoman 7y agoYes! I was waiting for this so long, Typescript is the most flexible typed OOP language and it's way more than just a JS successor.
- hutzlibu 7y agoOnly that this subset has no objects and is therefore not a OOP language anymore (?)
- tantalor 7y agoIt does have objects: STS has at runtime four kinds of unrelated object types: 1. a dynamic map type has named (string-indexed) properties that can hold values of any type; 2. a function (closure) type; 3. a class type describes instances of a class, which are treated nominally, via an efficient runtime subtype check on each field/method access, as described below; 4. an array (collection) type.
- hutzlibu 7y agoOk, I did not read the specifications yet and just refered to the other comment. But your quote gives no indication of (prototyp or classical) inheritance?
- tantalor 7y agoSTS classes are compiled similarly to Java or C# with single inheritance and static memory layout. Don't know much about STS or TS but I assume the usual JS class syntax works as spelled out here: https://www.typescriptlang.org/docs/handbook/classes.html https://www.typescriptlang.org/docs/handbook/classes.html
- pornel 7y agoFrom the title it would seem it is boiled down to a completely statically-typed language, but it isn't. e.g. type casts are no-ops. Instead, every object access is type-checked at runtime. `any` still exists and for unions and complex types it still performs full lookup by name (instead of RTTI/tagged unions or such). So it's not really a static language, but a cut-down JavaScript runtime that instead of optimizing objects with hidden classes at runtime, does similar thing with vtables ahead of time.
- mmoskal 7y agoExactly. 'Static' refers to control flow which is static (no eval etc.). Handling of data is dynamic, with static types used as hints. It's also meant to run on a very constrained microcontrollers (think a few kB of RAM), and compile inside of a client-side webapp (both of which make it hard to use things like AssemblyScript).
- baybal2 7y ago> As a result, the use of scripting languages (such as JavaScript and Python) for microcontrollers is on the rise. I can not think of what they smoke claiming running a scripting language on an MCU. Microsoft seem to set its sights on breaking the MCU development after nothing has left to break on the desktop.
- Dork1234 7y agoPython was first created in 1991 where a top of a line computer ran at 50mhz and had 50 MIPS. A current generation MCU - ATSAMG51 easily runs at 120mhz, and devices are quickly moving up to the 500mhz range (https://groboards.com/giant-board/ https://groboards.com/giant-board/). There clearly is enough processor power to Python. StaticTypescript isn't even running scripted, it is compiled to native and has performance close to C/C++ developed code.
- darzu 7y agoHey HN, I work at MSFT on MakeCode.com [5] which is the primary user of Static TypeScript. Happy to answer questions. Michal and others who worked on STS more directly will probably be online in a couple hours. One important clarification: So far STS has been built specifically to target microcontrollers/MCUs. Initially it was targeted at the BBC micro:bit [0] for educational purposes and has since grown to support many more targets ([1],[2],[3],[4],[5]). The other dominant languages in this space are MicroPython and the AVR/Arduino language. The advantages of STS are beginner friendliness (makecode is a CS EDU platform), low-memory, small size and performance (relative to MicroPython). It's worth noting that in general STS is NOT faster than running JS in V8. How does it compare to MicroPython? - Error reporting: Because STS is statically typed and compiled, most program errors are caught in the editor before the program is loaded on the device. Furthermore, STS comes with a simulator that runs in the browser and so programs can be tested there before they run on hardware. For educational purposes, we found diagnosing issues on hardware to be really hard for students, so we try to catch and present errors as early as possible. - Performance: [3] is the best example of this. Usually we notice STS is ~10x faster than uPython while having a smaller flash and memory footprint. This makes running a game loop at 30FPS feasible on a 120x160 display (e.g. this [6] $25 device). How does it compare to AVR/Arduino/C/C++? - Modern language: STS, like TypeScript, heavily uses type inference, supports advanced types constructs like algebraic types (i.e. sum/union and product/tuples), supports ducktyping, has easy to use lambdas, has a light-weight syntax, and favors event-based programming. - Teachability: Because of the heavy use of type inference, most beginner programs have no type annotations and it looks just like Javascript. So we essentially teach JS to users after they want to move on from blocks. - In general STS is not faster or smaller than AVR code! Happy to answer other questions! [0] https://makecode.microbit.org https://makecode.microbit.org [1] https://makecode.adafruit.com https://makecode.adafruit.com [2] https://maker.makecode.com https://maker.makecode.com [3] https://arcade.makecode.com https://arcade.makecode.com [4] https://makecode.mindstorms.com https://makecode.mindstorms.com [5] https://makecode.com https://makecode.com [6] https://www.adafruit.com/product/3939 https://www.adafruit.com/product/3939
- _bxg1 7y agoExtremely interesting idea. Sounds like many of the things they get rid of are some of the more problematic features of JS anyway. The end result is fairly Swift-y; a loosely OOP static language that has closures and really convenient hash-map syntax.