Live data from Hacker News

Learn how to unleash the full potential of the type system of TypeScript

type-level-typescript.com

251–256 of 256 posts

Re: Learn how to unleash the full potential of the type system of TypeScript

#251

Earlier quoted context omitted.

Thanks for the EU detail! Are you saying the typical house in the EU has three phase power delivered to it? All three phases? Here in the US, where split-phase is the residential standard, a house with three phase is quite rare. The HV lines running on poles in a neighborhood are mostly single phase, at least in rural areas like mine.

> Thanks for the EU detail! Are you saying the typical house in the EU has three phase power delivered to it? All three phases? Yes! And many electrical devices rely on it, though sometimes fallback to regular 230V single-phase at 32A is possible, e.g. for stoves. And considering a typical stove runs at 11-15kW and a typical electric water heater between 15kW to 25kW, you'll need it as otherwise you'll need far highe…

Although I use a propane range, I'm wired for a 240V 30A electric one. That's only 7.2KW. My water heater is also propane.

I have a friend with a Bridgeport vertical mill in his garage/workshop. He had to build a single phase to three phase converter, so he could run its three phase motors.

Re: Learn how to unleash the full potential of the type system of TypeScript

#252

Earlier quoted context omitted.

You maybe just lack experience with more complex types. Which is totally expected, since you probably learned programming the runtime all the time, but not the typesystem - unless you come from one of those rare languages that have a similar powerful typesystem. But just like you probably struggled with and overcame many things before, it will be the same now. It's just that you can opt out of the typesystem in types…

I’ve used C++, C# and Java. Do these count as languages with complex types? I also used typescript a lot and have plenty of more complex types using generics and dynamic generation of types based on other types. The problem with typescript is that the types are very often wrong or needlessly complicated. Having separate type definitions from the library is stupid. Having types missing from @types/node is stupid. Many…

None of these count as a language with complex types in my opinion. C++ has templates but that's not to be confused with its typesystem.

I'm not saying typescripts typesystem is perfect and I'm definitely not saying that most people use it correctly. But at least it has great potential, compared to e.g. Java and C# which still fail to let me describe basic data types and operations in the typesystem.

Re: Learn how to unleash the full potential of the type system of TypeScript

#253

Earlier quoted context omitted.

The problem with that is that eventually you want to have the dependencies automatically injected (like how an IoC container would be used in a typical OOP application). Sure, there's solutions for this in the FP world, but in my experience they tend to have their own drawbacks. Admittedly, I've only ever used TS on the front-end (with no DI), so I've never really looked at what FP-style libraries exist for this.

Why do you need automatic injection? What the parent said is idiomatic FP

Because in typical back-end software, the dependency tree can get very big very fast. Having an IoC container means devs only have to declare direct dependencies for each service, rather than constructing the entire tree (and figure out the necessary ordering, etc).

Re: Learn how to unleash the full potential of the type system of TypeScript

#254

Earlier quoted context omitted.

The problem with that is that eventually you want to have the dependencies automatically injected (like how an IoC container would be used in a typical OOP application). Sure, there's solutions for this in the FP world, but in my experience they tend to have their own drawbacks. Admittedly, I've only ever used TS on the front-end (with no DI), so I've never really looked at what FP-style libraries exist for this.

You could model that with one function taking that dependency and returning a new one with it included. Then you just use the one that has it included instead of the one that doesn't.

You still have to construct and pass in that dependency though, along with all of its dependencies, recursively.

Re: Learn how to unleash the full potential of the type system of TypeScript

#255

Earlier quoted context omitted.

The problem with that is that eventually you want to have the dependencies automatically injected (like how an IoC container would be used in a typical OOP application). Sure, there's solutions for this in the FP world, but in my experience they tend to have their own drawbacks. Admittedly, I've only ever used TS on the front-end (with no DI), so I've never really looked at what FP-style libraries exist for this.

Are you seeing any decorator or OOP style in React? Yet plenty of dependencies are automatically injected without the OOP jargon, if you want to see a pure JS example of auto DI go check angular 1.5 dep system, and Vuejs.

> React

I totally agree there are other good/better options (as evidenced by react and many others), but I don't think this is an entirely fair comparison. The main "DI" alternatives in React are hooks, context, and imports, none of which could really replace traditional IoC containers on the backend without some modifications.

I think the main thing that makes automatic DI easy with OOP is the clear separation between dependencies (constructor parameters), and method parameters. Admittedly, this is totally possible with FP, but requires some good conventions and doesn't seem to be nearly as popular.

I also think most OOP langs have terrible syntax for constructors, which makes it look clunkier than it really is. Primary constructors (e.g. kotlin) make this not much more verbose than the FP alternative.

> Angular 1.5 dep system

Yes it's vanilla JS, but I doubt there's many FP people that would call that functional. The examples I saw are all just using JS functions as "discount classes", which definitely aren't pure or functional.

Re: Learn how to unleash the full potential of the type system of TypeScript

#256

Wow I think I know a lot of Typescript but I'll have to go through it because I'm always asked for ressources to get started and this one seem great. I also recommend type-challenges: https://github.com/type-challenges/type-challenges It works great with the VSCode extension.

> It works great with the VSCode extension. What do you mean? Which extension?

https://marketplace.visualstudio.com/items?itemName=YRM.type...
Post reply on HN