5 ms·
Ugh. You're going to make me defend Java? I'm going to need a drink... First point: Yes, Java's arrays are broken and it offends me greatly. However, in practi
by ragnese 5y ago
Ugh. You're going to make me defend Java? I'm going to need a drink...
First point: Yes, Java's arrays are broken and it offends me greatly. However, in practice, it's much more common to use Lists, which are not broken. In JavaScript/TypeScript "Array" is the equivalent of Java's List, so if you want a dynamically sized, contiguous, collection, you are stuck with the broken thing.
Then, the other issue is that, despite my comment's wording, this problem isn't ONLY present in Arrays. It's also a problem with objects, and (I assume) every other non-primitive type. See here: https://www.typescriptlang.org/play?#code/MYGwhgzhAECCB2BLAtmE0DeBfAsAKFEhgGEwAXaAUwA8zL4ATGBFNTfaT6ZSgewHcAFAEoAXNABuvRA3Z4uC6MF7wIvEJQB0IXgHNBAIh4CDwjl1x5LhKNAAieqrXpM4SVOgznOAIzAAnAGsRcSkZOUUuZVV1LR19Az8g029oS0t8RHg6fwAzMGBKaAAJSAAFSgoveS4AB0rxFg98DLwsnPzCksgHXQi6hvs9Fvx8XIBXeGAyRBVuMCRa8fA6CrJBXnFSiDXhfs5eTXqKAF5oeEp+aFJ1sytRghUICk3uiF7oM+qFY-ELq96IhGeHwqEWy3IlDWGzu+EOx00SWCewA9CilLxkLVEBp-NBEDB6nlKNMQABPaAACzAtVqZIAhEA https://www.typescriptlang.org/play?#code/MYGwhgzhAECCB2BLAt...
So even a basic object field is broken in TypeScript's type system. What the hell are we supposed to do with this?
I do have thoughts and opinions about Java's Collection interfaces, the immutable implementations, etc, but that feels like a whole other topic.
- jakear 5y agoYes, TypeScript’s type system is unsound. Yes. Flow handles some of these cases better, but the invisible keyboard of the market has decided that the extra conceptual/syntactical overhead of introducing co/contravariant types is not worth it for these corner cases. You may disagree, that’s fine. But I’d suggest treating the problem as the engineering tradeoff that it is rather than an absolute fact that every type system must not have any holes and those that do are worthless.
- ragnese 5y agoThe invisible keyboard of the market... guided by millions of dollars from Microsoft, I assume. > rather than an absolute fact that every type system must not have any holes and those that do are worthless. Also, don't straw man me, please.
- jakear 5y ago> So even a basic object field is broken in TypeScript's type system. What the hell are we supposed to do with this? > So a hole exists in TypeScript's type system. What the hell are we supposed to do with this? > So a hole exists in TypeScript's type system. How can this be useful? > A hole exists in TypeScript's type system, therefore it is not useful. > Every type system must not have any holes and those that do are worthless. Where's the straw? Regardless, the issue you pose is solved via generics, which would be the appropriate TS way to model this: https://www.typescriptlang.org/play?#code/MYGwhgzhAECCB2BLAtmE0DeBfAsAKFEhgGEwAXaAUwA8zL4ATGBFNTfaT6ZSgewHcAFAEoAXNABuvRA3Z4uC6MF7wIvEJQB0IXgHNBAIh4CDwjl1x5LhKNAAieqrXpM4SVOgznOAIzAAnAGsRcSkZOUUuZVV1LR19Az8g029oS0t8RHg6fwAzMGBKaAAJSAAFSjIAHgqKAF43VhAAPgiuAAdK8Vr8DLwsnPzCksgHXTbOTrJxMd78fFyAV3hgMkQVbjAkdsXwOlqayoAVAE9O5sFecVKIA9rT8+EJ6F5NKegG+Ep+aFIyETmeHw0QgFCuIwgYw+zym4i+PzGAKs8zwqG2u3IlFqlzMQLwrymmiSwSeAHpSUpeMh2ogNP5oIgYJ08pRViATtAABZgdrtE4AQiAA https://www.typescriptlang.org/play?#code/MYGwhgzhAECCB2BLAt... Similar constructs would solve your proposed Array issues too: https://www.typescriptlang.org/play?#code/MYGwhgzhAECCB2BLAtmE0DeBfAsAKFEhgGEwAXaAUwA8zL4ATGBFNTfaT6ZSgewHcAFAEoAXNABuvRA3Z4uC6MF7wIvEJQB0IXgHNBAIh4CDwjl1x5LhKNAAieqrXpM4SVOgznOAIzAAnAGsRcSkZOUUuZVV1LR19Az8g029oS0t8RHg6fwAzMGBKaAAJSAAFSjIAHgqyABUATwAHIoBeN1YQAD4IrhaycVrGlvwMvCyc-MKSyAddXs5+8TnR-HxcgFd4YDJEFWgwBgZSarqnOkZmdzQuwQD-cTqAbQBdYQWD-39NJo2IAAtBPBKPxoCcRGYrEA https://www.typescriptlang.org/play?#code/MYGwhgzhAECCB2BLAt... TS is explicitly designed to be easy to apply to existing codebases without terribly much work. This means it must allow unsound code in some cases. However, given it also provides mechanisms to make the code sound, I do not see why this must be a dealbreaker to you. I think if you took the time to learn it you'd find the type system is actually quite powerful. (Disclaimer work at MSFT on their TS editor)
- ragnese 5y ago> Where's the straw? Seriously? The very first transformation you did was a straw man. There are two concepts here. Do you understand that two things can have different importance? Do you also understand that some numbers can be larger than others? For example, 10 > 1. So, "basic object field sub-types" is a pretty damn big error. Furthermore, I didn't say that this one issue made it worthless. I do think TypeScript is nearly worthless, but if this issue were the single issue with TypeScript, I might not say it's worthless. However, we have this issue, which is a big deal, and we have MORE than one of these type issues. So, the statement "every type system must not have any holes and those that do are worthless" is not even what I think at all. A small, niche, edge case of a type hole would not make a language as shitty as TypeScript, and therefore would not qualify as a worthless type system, automatically. No, it's the fact that TypeScript's type system has MANY (>1) type soundness/correct issues, and some of them are quite serious and fundamental. Using generics to "fix" the problem is a work around. It does not somehow make TypeScript's compiler correct. The fact is that the type system is broken/incorrect. There should be no need to use generics, and generics aren't somehow more correct in a type-theory sense. > I do not see why this must be a dealbreaker to you. You don't have to. But, I've had to research strange, inconsistent, incorrect behavior in TypeScript way too many times in the last few months. This is a bad language where a signficant amount of the type system is only giving a false sense of security/correctness. > I think if you took the time to learn it you'd find the type system is actually quite powerful. I've spent the last year learning WAY more about TypeScript's type system than I should need to. It isn't powerful at all if it's incorrect. Readonly types don't work, sub-type relationships don't work, generics sometimes don't work right/expectedly- where's the "power" in that?