Live data from Hacker News

Google Feedback on TypeScript 3.5

github.com

141–149 of 149 posts

Re: Google Feedback on TypeScript 3.5

#141
post #101

Earlier quoted context omitted.

All types are optional in typescript. I was just curious about Google's approach to it and if they had some standard practice of always copying the inferred type to get a great amount of coverage.

Copying the inferred type is the same as copying your runtime outputs into your tests. It's a statement that you believe the result is correct and it's on you to make that judgement call. It's not a policy to blindly copy everything, because that defeats the purpose of type checking and testing, turning your tests into " verify that nothing changed", not "verify that the system behaves as intended".

Thanks, thats typically how I approach it as well, it's good to hear it written out. I try not to append copied types without fully understanding their structure either. But sometimes you just need to just trust it to solve a problem.

There's plenty of blog posts and docs on advanced types but I'm interested in the day-to-day best practical approaches people are taking adopting it. I should look around for some literature or talks on the subject...

Re: Google Feedback on TypeScript 3.5

#142
post #107

Earlier quoted context omitted.

I tried using it with Angular, but it doesn't seem to help much. For example, if you have something like: And then a TypeScript function like: login(email: string, pass: string) { } TypeScript can't help you at all here because all the typing is determined at runtime by Angular. Even if `email` is a number or a boolean, no problem, it will just happily pass it in. What benefit, then, does TypeScript provide? I unders…

For your template code in angular, there won't be any significant benefit to using typescript. It could be worse than not having typescript at all, since you can add type annotations to your 'login'-function that don't match up with reality. That's not really a typescript issue though, and it works great with libraries that don't use string templates. From what I've seen the angular community hasn't really prioritize…

Nor does Vue. The focus is on typing the reactive data that feeds the templates which should be sufficient.

Plenty of things like HTML form elements take numbers or strings just fine, as it all outputs to strings in the end. Additionally, by breaking up stuff into smaller composable components there should be enough gating and typing layers, at least with Vue/Vuex that's the case. If it was just plopping straight into the elements 1-to-1 that might be a different story.

Re: Google Feedback on TypeScript 3.5

#143
post #111
post #34

Earlier quoted context omitted.

> Although it usually isn't necessary, it makes drastic improvements to the quality of error messages. It also provides valuable documentation. You can usually work out what a function does from just its type (and quite often, that's all you have to work with).

> just its type (and quite often, that's all you have to work with). which is a weakness in the culture of Haskell library authors and/or the ecosystem for contributing documentation patches.

Couldn't agree more. My recent experiences with Rust and especially Elixir have set high standards.

Re: Google Feedback on TypeScript 3.5

#144
post #53
post #35

Earlier quoted context omitted.

Have you looked at ReasonML/OCaml? It certainly compiles well for web (bucklescript) and desktop. I haven't tried it for mobile but I would be surprised if it didn't work well. The ReasonML native tooling (i.e. non-web) is evolving, but it's fundamentally sugar on top of a long solid history of OCaml.

I'd love to have ML expressiveness. The only thing i'm a bit worried about is the I/O abstraction level. I'm not really looking for a GUI abstraction layer, but i'd like to be able to write to a file, or perform a network request, in a platform-independant way. I'm afraid this requires a little bit more than just a javascript transpiler target.

Reasonml is just an alternative syntax for ocaml so you can definitely use it for IO.

It's bucklescript that is an alternative backend for the ocaml compiler which allows you to output js, but you don't need to use it

Re: Google Feedback on TypeScript 3.5

#145
post #53

Earlier quoted context omitted.

I'd love to have ML expressiveness. The only thing i'm a bit worried about is the I/O abstraction level. I'm not really looking for a GUI abstraction layer, but i'd like to be able to write to a file, or perform a network request, in a platform-independant way. I'm afraid this requires a little bit more than just a javascript transpiler target.

Reasonml is just an alternative syntax for ocaml so you can definitely use it for IO. It's bucklescript that is an alternative backend for the ocaml compiler which allows you to output js, but you don't need to use it

That's where my understanding of compiler / Operating system / standard library falls a bit short.

I suppose the full ocaml standard library isn't available when you compile your code to native iOS or native Android, is it ?

I mean, iOS and and Android are probably not POSX compliant. File system and networking access have very specific constraints, that are way different than your regular server. At least that my feeling whenever i code in iOS. Your application needs to whitelist URLs in a plist, you need to work with foreground / background states (eg timer are paused when in background). I can't imagine that the standard ocaml library doesn't need adaptation to run in those environment.

Am i wrong ?

Re: Google Feedback on TypeScript 3.5

#146
post #37
post #26

Earlier quoted context omitted.

Did they improve the download size?

No and on that basis it's unusable. However that's because it downloads the whole runtime. Eventually MS intend to load only your compiled code.

I would not be so categorical.

I have a data web-app heavy app where users will routinely view over 300MB of data in charts and photos. In this context, .net runtime is insignificant. In fact, you could could argue such data intensive applications should be native and use local storage. Lastly, the browser with cache .Net runtime, and won't download it very often.

Re: Google Feedback on TypeScript 3.5

#147

Earlier quoted context omitted.

IIRC there are a couple of Rust write ups about this. In Rust, inference is limited within functions. The language doesn't allow inferring the argument or return types of functions to avoid this kind of action at a distance. The function API is just one of the many arbitrary places where one can limit inference and require users to provide types. In other languages the module boundary might also be an appropriate pla…

The compiler should be capable of inferring the type as far as reasonably possible. But it should be an error to not specific the types of top level functions and class methods. This way, when you write const f = (a, b) => a + b the compiler can tell you to write: const f => (a: T, b: T): T => a + b or const f : (a: T, b: T) => T = (a, b) => a + b This would be effectively like GHC's typeholes, where the compiler wil…

I don't think typeholes is necessary for that feature. It suffices to just use type check up to the function signature. If I write:

    fn foo() { 42 } 
in Rust, I get an error that says that `i32` (the type of `42`) is not of type `()` (unit), which is the return type of `foo`. So I can just change it to:

    fn foo() -> i32 { 42 } 
instead. The same applies for generics, if I write:

    fn bar(x: T, y: T) -> T { x + y }
I get the precise error that T does not implement the `Add` trait. In this case the error is precise because there is only a trait in scope that supports `+`, but once there are many traits that would fit, which is rare, the compiler suggests some (often all of them). With that error I can just change that to:

    fn bar(x: T, y: T) -> T { x + y }
This is all done through local type inference within the function.

Re: Google Feedback on TypeScript 3.5

#148
post #116
post #47

Earlier quoted context omitted.

Mostly it means that you have to be really thoughtful when introducing a breaking change to a low level library.

Or you can YOLO / Leroy Jenkins the change and let everyone else fix the breakage you create, or see if they demand a rollback.

They will not only demand a rollback but also do it. Besides, low level changes at this scale require a copious amount of approvals.

Re: Google Feedback on TypeScript 3.5

#149
post #109

Earlier quoted context omitted.

If you do go with TypeScript have a look at Nx. It's tooling around TypeScript monorepo that helps you do exactly what you want: write code once and share it between backend/multiple frontends. It suppports Express or NestJS in the backend and Angular, React, Web Components in the Frontend. https://nx.dev/ If you want to make it work with Ionic/NativeScript/Electron as well use xplat. https://github.com/nstudio/xplat

I don’t see anything regarding mobile platform (native).

True, it's not possible because you need to write your code in Swift / Objective-C for iOS and Kotlin / Java for Android. And Nx only supports TypeScript.
Post reply on HN