Earlier quoted context omitted.
I'd love to see an explanation of monads that accurately captures their capabilities in terms no more complex than those required to do the same for promises.
I had a pop at this here https://dev.to/choc13/grokking-monads-in-f-3j7f
Tricks I wish I knew when I learned TypeScript
251–260 of 276 posts
Re: Tricks I wish I knew when I learned TypeScript
#252Re: Tricks I wish I knew when I learned TypeScript
#253Utility Types[0] will help you get to the next level on Typescript. It's important to know them and know how and when to use them. [0] https://www.typescriptlang.org/docs/handbook/utility-types.h...
Re: Tricks I wish I knew when I learned TypeScript
#254Does Typescript get better? I've been forced to use it for my most recent project, but haven't been given any time to read through the documentation. I've found that I'm spending about 99.9999% of my development time trying to figure out how to get my IDE to not show that their are typescript problem. At this point I hate typescript with the burning fury of a trillion suns. I wonder if this is everyone else's experie…
Re: Tricks I wish I knew when I learned TypeScript
#255Earlier quoted context omitted.
exactly.. the 'only' billion dollar mistake in JS in regards to null is that typeof null === 'object' => true
It’s not undefined, therefore it’s an object. And because every type can be null, it makes sense that it’s just “object”, not “string” or whatever.
it is an implementation bug of netscape, null was represented by the zero pointer and objects where tagged pointer with a tag of zero, so when reading its tag null looked like an object.
there are solutions as x == null, x === null, and Object(x) == x allow you to check for null|undefined, null, and object values, but typeof null being "object" is purely a specification bug that it is too late to change.
Re: Tricks I wish I knew when I learned TypeScript
#256Earlier quoted context omitted.
exactly.. the 'only' billion dollar mistake in JS in regards to null is that typeof null === 'object' => true
It’s not undefined, therefore it’s an object. And because every type can be null, it makes sense that it’s just “object”, not “string” or whatever.
It would kind of make sense in Java, where only object types can be null. But that distinction does not exist in JavaScript.
Re: Tricks I wish I knew when I learned TypeScript
#257Which is a good thing, because in reviewing those I found several places where incorrect assumptions were being made about the type of error that would be caught.
(side note: TypeScript does not follow SemVer; they just promise to avoid breaking changes in Patch updates, but don't promise anything won't break in Minor updates [1])
[0]: https://devblogs.microsoft.com/typescript/announcing-typescr...
[1]: https://github.com/microsoft/TypeScript/issues/14116#issueco...
Re: Tricks I wish I knew when I learned TypeScript
#258Earlier quoted context omitted.
The advantage here is that you are not repeating the type of the property twice (once as optional in the base type, once as mandatory in the extended class). Even though the code may seem inscrutable, note that the resulting type is fairly easy to understand in your IDE. That is, if you hover over the "B" to see what the type definition is, you see: type B = A & { foo: number; baz: number; } If you defined the type l…
The beginner programmer copies the property definition. The advanced programmer simply writes "type Ensure = T & { [U in keyof Pick ]-?: T[U] };", thus removing the need to copy the property. The master programmer copies the property definition.
I'm not sure how often you would need type helpers in application code, for frameworks and libraries they are a godsend.
Your argument is a bit like saying we don't need parameterized types like Array because you can just copy paste the code for each type.
Re: Tricks I wish I knew when I learned TypeScript
#259Still working on this, but might give someone a laugh :) Problem 1 from Project Euler in TypeScripts Types https://github.com/iiTzEddyGG/typing-euler/blob/master/src/p...
I am highly interested in type programming lately, exactly the kind of thing you're doing here. Do you have any other resources that inspired you? Here are some of my favorites: https://gist.github.com/hediet/63f4844acf5ac330804801084f87a... https://github.com/codemix/ts-sql https://github.com/jamiebuilds/json-parser-in-typescript-ver... https://gist.github.com/acutmore/9d2ce837f019608f26ff54e0b1c...
Re: Tricks I wish I knew when I learned TypeScript
#260Earlier quoted context omitted.
Array.isArray[0] is your friend [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Did anybody else have their brain do a weird backflip seeing `Array.isArray[0]`?? Object.getOwnPropertyDescriptors(Array.isArray) /* { '0': { value: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray', writable: true, enumerable: true, configurable: true }, length: { value: 1, writable: false, enumerable: false, configurable: true }, name: { value: 'isArray', writable: fal…