TypeScript at Google (2018)
neugierig.org
neugierig.org
(Disclosure: I work on ads at Google, speaking only for myself)
Hence plenty of companies still on Java 8, baby steps adopting C++11, Python 2.7, .NET Framework 4.8 is now being deployed, and similar....
Installing whatever you feel like locally doesn't work, because either you miss the required rights, or it will die on the CI/CD pipeline anyway.
There is active work to improve this and make external does a first class feature. It will improve as more external contributors work on solutions and adopt bazel.
> not all languages are equally well supported
Similar to the previous statement. It doesn't make sense to imply "it's not perfect so it will never be perfect". The vision and feature set makes sense to me and I see no other build system tackling this scope.
> and for small shops it's probably stupid to add build files everywhere.
What makes it stupid? If your team is so small that you're only building one binary you only need one BUILD file. Very similar to how Gradle works actually.
Also, build files are mostly auto generated if you wire your source code to standard conventions. It's something you only need to think about or touch when doing something complex (that also is not supported by other build systems). Example: using genrules to automate something or packaging things for deployment.
If you have:
- more then one language
- unit tests
- package an artifact for deployment (Docker, tar, zip, etc)
- can benefit from caching
Bazel-likes are pretty much the only option right now.
There are quirks but there's also a growing community trying to smooth out those areas.
The solutions I engineered still had to make some compromises and better solutions by dedicated teams were built later on, of course. All this just to say that I can very readily sympathize with the challenges that Googlers must be facing.
Edit: To clarify, I put in my 2-week notice a while back and today was my last day. That's what I meant by "resigned today".
I'd been at Amazon for many years and had always wanted to move on to doing my own startup, which is what I'll be doing starting tomorrow. It's an exciting moment for me. My biggest worry about leaving is figuring out what to do about health insurance, but my fallback plan is to go with COBRA until I figure something out.
Overcoming the incompatibility of npm's multi-version allowance and Brazil's need to have a single version of each package in the transitive closure of the dependency graph without hacks like shrinkwrapping was a key turning point.
For frontend it might be different, but as someone who usually touches the Js ecosystem through node, I pretty much won't use Js.
Like why should I give up insane utility with negligible (if any) runtime cost, high configurability (with sane defaults), easy buy in (since all Js is valid Ts)?
Maybe the last part is what you're missing? Most "layers on Js" needed you to rewrite or annotate all your code to get and value at all.
But you drop a tsconfig in a project and you instantly get value out of it. What past layer on Js had that?
I find that as long as the code is reasonably straightforward, I get most of TS's benefits without actually declaring any types. It was kind of a pain to originally set up, but the code hints really are pretty magical.
/** @type {import('../index').Engine} */
this.engine = engine
Most of my projects have a god object at the center, so if I explicitly type that one object then I get basically all the important code hints for free.A side benefit of this is that you can also use TypeDoc to generate docs. It's not really made for vanilla JS, but once I got over the initial road bumps I've been happy with the results.
At this point the features that ts has and reason doesn't out number that of the other way around. I only know that reason has more stringent jsx types and opaque types (easily done in ts in 2 lines of code). On the other hand ts has mapped types and conditional types, weird as they are, pretty unique to itself. In the future, expect ts to be even more functional and absorb ideas from F# which is also from microsoft.
You can't do that with ReasonML, you are forced to adopt another language that is not Javascript.
As others will point out alot has progressed and changed since then, this isn't news.
Lots of previous discussion: https://news.ycombinator.com/item?id=17894764
Guess that means Gmail is now 17 years old.
My company has roughly the same # of engineers as Google and has had some teams that adopted TypeScript while others didn't. We even own a product that uses Flowjs, for some reason. It didn't require a huge rigamarole to do so, just a hook into the internal build system (which, looking at it now, is significantly smaller in surface area than the rules_typescript Bazel rule).
It’s also a huge company with a gigantic monorepo (there’s papers about it elsewhere) and a lot of inertia.
It’s amazing what Evan and his team were able to do for front-end development at Google by building tools to bridge between Google JS and TypeScript.
The monorepo aspect of the story just seems to just make doing this significantly more difficult for no discernible benefit. Isn't this the same team that made that 5 page issue on the TypeScript Github page complaining about a version bump?
It has many other benefits as well that have been outlined in lots of other posts.
It's well written too; a good model for design / discussion papers.
1 - Work-arounds for interoperability with non typescript / legacy third party dependencies. (issue: ugly, non consistent code)
2 - Turn off strict type checking due to third party component compatibility. (issue: isn't the purpose of typescript type checking?)
3 - Is type checking really needed for most applications? (assuming some flavor of CRUD with the occasional special sauce). (issue: seems a bit academic unless your working on a webapp for the mars rover)
This is coming from someone who programmed in java, .net, strongly typed languages for years and then feels like javascript is being held back with typescript. I love programming in vanilla javascript using frameworks (in this order) vuejs, reactjs, and charge extra to work on angular.
Many libraries come with TS support out of the box and the autocomplete and automatic renaming across files is quite nice.
I'm using strict mode and didn't have issues yet, but I'm just at the beginning, so let's see how it goes.
2 out of 3 of the items you wrote down has to deal with old baggage, so whatever form of language you are dealing with those, you aren't going to have a good time. You can either bite the bullet and write the type definitions yourself, or just disable the type system altogether, which, if you can isolate it to a certain area in the code, you are fine.
If you are writing code that some other person is going to read and/or you are interested in having it behave reliably in the long run, I think a static type system is a must. Coupled with good unit tests, if the type checker does not complain, you can be very confident the code you wrote is working and will work for a vast majority of the cases.
Typescript is especially great because, unlike some other statically typed languages, you can choose not do use it in some cases (e.g., setting up mocks for tests, writing a small script to see how stuff works, etc), which is liberating.
I went from Python to Typescript. Python is still my go-to language for random tasks, though unless I have a good reason to do otherwise, I don't want to deal with a production codebase that does not do static type analysis anymore. I don't know others, but I just get more done in less amount of time in this way.
Can’t this be accomplished with JavaScript? Assuming your interested in clean code and best practices.
“Coupled with good unit tests”
Can’t you also write unit tests in JavaScript?
“if the type checker does not complain, you can be very confident the code you wrote is working and will work for a vast majority of the cases.”
This is a false sense of security. “Compiling” without errors just tells me I did not do something dumb like assign a string to an int. Is this really the main issue devs have? From what I have seen no… Devs usually need to chase down and understand the code regardless of type checking.
Thanks for your perspective!
Word on the street says that C programmers are usually expert engineers that know what they're doing. Yet, I had to deal with those conversion errors all the time. That C code isn't a random CRUD application on a simple website. That can be software embedded in controllers in sensitive equipment, or equipment that will be harder to update. So it's even more important to get it right. And yet...
There's nothing that prevents you from swimming against a stream, but we know swimming with the stream is faster. Same thing here. It's not impossible in javascript, but typescript makes code maintenance much more easier.
> Can’t you also write unit tests in JavaScript?
"Being more than sum of its parts" and all that.
> This is a false sense of security. “Compiling” without errors just tells me I did not do something dumb like assign a string to an int. Is this really the main issue devs have? From what I have seen no… Devs usually need to chase down and understand the code regardless of type checking.
Typescript does not solve all the software engineering problems. It makes common problems and annoyances much more easy to handle.
I disagree. Working towards a successful "compile" isn't much different than TDD. The number of runtime errors I run into is significantly lower with TS than it ever was without which gives a very real sense of security.
You do need to understand the code but without types it can be very difficult to track down all the places that need to be fixed when you need to change your data model. Types are more important for refactoring than writing IMO
I recently had to take over development of a fairly large legacy application and the first thing I did was convert the core of it to Typescript, that process uncovered a lot of bugs around handling of input/output especially lack of null/undefined checking. Typescript replaces a lot of the effort that used to spent on JSDoc type annotations and unit tests (of course tests are still required but it reduces the scope of possible input from any possible type to a smaller subset).
One thing that works really well with Typescript codebases is to push the untyped code (such as legacy libraries) and input validation to the edges of the application, and ensure the core is fully type safe.
These "workarounds" are typically to use third-party or hand-rolled type defs. The other common case is to write and use typeguard functions that do runtime type checking but can contextually narrow types inside conditional blocks that use them. It's a little extra work, but the ROI is there, in my experience.
> 2 - Turn off strict type checking due to third party component compatibility. (issue: isn't the purpose of typescript type checking?)
I've never seen this done. I'd always take one of the approaches I mentioned above.
> 3 - Is type checking really needed for most applications? (assuming some flavor of CRUD with the occasional special sauce). (issue: seems a bit academic unless your working on a webapp for the mars rover)
The productivity gains alone make it worth it, IMO. Refactoring without worry that you forgot to maybe update one place is just so freeing. Amazing auto-complete and intellisense makes it so much easier to work with third party libs you're unfamiliar with. And the best part is of course that many simple mistakes get caught before you even run your code at all. It takes me less time to write TS code than it does to write the equivalent JS in even simple projects. A higher likelihood of writing correct code is valuable in just about any setting, not just space projects.
I think it may take a little bit of time for things to "click", but once they do, it's usually much faster/easier/safer to work in TS.
1 - there is very little third-party JS at Google due to historical issues interoperating with the Closure compiler, as documented in the post.
2 - Strict type checking is used and continually made stricter.
3 - Yes, when you have thousands of engineers contributing to the same code base for some quite sophisticated web applications, type checking is extremely useful.
1 is almost a non issue. Most libraries have decent types and TS has features for adding types yourself in your project.
2 - I've never had to disable strict mode to get a library working. Worst case you can use things like `any` as an escape hatch out of TS but it is usually tucked away in a black box that is nicely typed. Do you have examples?
3 - Correctness is important for most professional software not just billion dollar NASA projects. Runtime errors cause crashes which wrecks UX.
For programming in it on anger, only when the underlying framework is also written in Typescript.
It is so liberating to just code in JavaScript with a plain <script/> include, without the pleothora of FE build tools.
Maybe one day browsers will actually replace JavaScript with Typescript.