Live data from Hacker News

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

type-level-typescript.com

141–150 of 256 posts

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

#141

A great idea. Now, everyone that learns this stuff, show some restraint! The drawback of a powerful type system is you can very easily get yourself into a type complexity mudhole. Nothing worse than trying to call a method where a simple `Foo` object would do but instead you've defined 60 character definition of `Foo` capabilities in the type system in the method signature. Less is more.

My coding philosophy is centered around simple interfaces. I think of power sockets and plugs. The simpler the socket/plug design, the easier it is to plug in. It's easier to connect a European plug which has 2 round pins than it is to connect a UK plug which has 3 rectangular pins at different angles. You can imagine how difficult it would be to connect a plug with 10 pins; it would be difficult to get the alignment…

I love the socket/plug analogy.

It's even better than it looks in Europe: there are actuality 3 contact points but only 2 are salient which allows for 2 easily pluggable positions (rotate 180deg). The ground is positioned twice for that matter.

Only France has a variation around that to my knowledge, that is still compatible across Europe.

And no one notices and just plugs in and out without thinking twice about it.

There are some unsung heroes here.

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

#142
post #22
post #18

Earlier quoted context omitted.

The Id type defined in the first comment seems like a pretty good, albeit ideally unnecessary, workaround.

Those hacks work but in practice I wouldn't classify them as "good". You end up having to look at a ton of types including in library code like React and etc that can be quite complex. Having to stop and try to wrap those on the fly is terrible ergonomics.

You might also be able to leverage typeof in conjunction with Id. Like if you have some parameter x with a complex type you can create a temporary variable of type Id to avoid looking up any additional types. Totally agree it should be supported out of the box, however.

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

#143
I currently have to occasionally contribute to a TypeScript codebase at work. I appreciate how much better it is than Javascript. When I write code as an outsider (Java and Go developer), I feel like I use the type system in sensible and readable ways. When I look at the code written by the native TypeScript experts in my company it is a bewildering, abstract, unreadable morass. I have no idea what's going on half the time.

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

#144
post #90

Earlier quoted context omitted.

That boundary is why I have a hard time taking TypeScript seriously. A type system that doesn't participate in code generation is what.. just for linting and documentation basically? Is that what we are become? Is that all people think a type system is good for? Worse there is one value that is both a user-definable TypeScript type and a JS value.

> That boundary is why I have a hard time taking TypeScript seriously. A type system that doesn't participate in code generation is what How is being able to check code correctness at compile-time even close to "just linting and documentation basically"? This has to be a bad faith argument > Worse there is one value that is both a user-definable TypeScript type and a JS value. What does this even mean? I don't think…

It's just fancy documentation. It doesn't contribute to behavior at all. Typescript can describe polymorphism, lamely, but it can't drive it.

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

#145

Might as well ask here. On our teams, we have the occasional developer that is insistent on using Typescript in an OO fashion. This has always struck me as square peg round hole. Even though I come from an OO background, Typescript strict settings really seem to push me in a direction of using interfaces and types for type signatures, and almost never classes, subclasses, instantiated objects. I don't have a very goo…

We use Classes extensively in our code because it is an Electron app that interfaces with hardware. OO Typescript is incredibly useful, as we have clearly defined objects and inheritance schemes that would be a nightmare in native JS. The syntactic sugar of TS classes delivers an enormously powerful verification system.

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

#146
post #120

Earlier quoted context omitted.

Maybe in a controlled environment Typescript can produce benefits - however much of my argument is that our environments are typical uncontrolled , let's not give the monsters any more magic than we have to.

I’m inclined to say that any magic applied here is a win. Making things complicated with Typescript is simply hard enough that those people that’d mess things up in the first place wouldn’t even consider trying.

Yes, let's write everything in assembly language. Only the real pros will dare touch that! /s

Complex to understand code does not entail high quality of maintainers. Quite the opposite in my experience.

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

#147

I currently have to occasionally contribute to a TypeScript codebase at work. I appreciate how much better it is than Javascript. When I write code as an outsider (Java and Go developer), I feel like I use the type system in sensible and readable ways. When I look at the code written by the native TypeScript experts in my company it is a bewildering, abstract, unreadable morass. I have no idea what's going on half th…

Yeah, what a terrible syntax :(

Just today I was looking at the type definition for a third-party lib (ramda)... what the heck does this even mean...

compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T6;

Got it?

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

#148
reminds me of C++ templated types being used for similar... except in this case there is no performance advantage from removing run-time logic by force.

this kind of stuff is often confusing when working with teams. using simple dumb stuff is always the better option when you can.

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

#149

A great idea. Now, everyone that learns this stuff, show some restraint! The drawback of a powerful type system is you can very easily get yourself into a type complexity mudhole. Nothing worse than trying to call a method where a simple `Foo` object would do but instead you've defined 60 character definition of `Foo` capabilities in the type system in the method signature. Less is more.

My coding philosophy is centered around simple interfaces. I think of power sockets and plugs. The simpler the socket/plug design, the easier it is to plug in. It's easier to connect a European plug which has 2 round pins than it is to connect a UK plug which has 3 rectangular pins at different angles. You can imagine how difficult it would be to connect a plug with 10 pins; it would be difficult to get the alignment…

https://www.youtube.com/watch?v=baY3SaIhfl0

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

#150

I currently have to occasionally contribute to a TypeScript codebase at work. I appreciate how much better it is than Javascript. When I write code as an outsider (Java and Go developer), I feel like I use the type system in sensible and readable ways. When I look at the code written by the native TypeScript experts in my company it is a bewildering, abstract, unreadable morass. I have no idea what's going on half th…

Yeah, what a terrible syntax :( Just today I was looking at the type definition for a third-party lib (ramda)... what the heck does this even mean... compose (fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T6; Got it?

It's very simple to understand. You don't have to actually read the definition just know what "compose" does at a high level.
Post reply on HN