August 18th, 2020

(no subject)

Saw on reddit an old screenshot from a slack channel of a company founded by a couple of Slavs (a Russian and a Ukrainian):



Not sure how I feel about this, apart from being appalled by the climate in which employees are set against one another because their bonus depends on the performance of their teammates. Could be a shitty place to work in; although who knows, maybe there are functional teams in there as well.

(no subject)

I love typescript. But right now, I am swearing at the screen, because I can't understand the logic of it.

Typescript has a keyword extends. Which can be used in this traditional context, where a class / object / interface extends an interface:



In this case, we are saying that whatever we are declaring (Square, in this example) will have all the properties declared on the parent interface, and may add some more. Surely, it produces a superset of types conforming to the ancestral interface and adding some extra properties. This is what the word to extend means.

But at the same time, typescript can do this:



What the hell? The word extends is used here to define a subset of a type?! I.e. in a completely opposite sense than in the previous example? How can you even use the word "to extend" to mean "one of"?

Then, of course, we have this:



A nice generic function, whose type could be written like this:



or should it be like this:



No, really, both notations are valid; they must mean different things; in this particular case I want type Bar; but when do I want type Foo? The first type definition (for Foo) makes the function a generic type; so when a variable of this type is declared, another type has to be passed to the generic. The second notation (for Bar) is not describing a generic type. Is it "generic constraints" as mentioned in Typescript Handbook? I don't know; the handbook is not using arrow functions, and I cannot see how the types defined in the section on generic constraints are different than the types defined in the section on generic functions.

Despite its huge popularity, documentation for typescript leaves a lot to be desired.