Live data from Hacker News

TypeScript 3.7

typescriptlang.org

81–90 of 167 posts

Re: TypeScript 3.7

#81
post #19

Great incremental release. Typescript really isn't the most exciting language, but it's very very helpful. Compared to regular javascript it saves me a lot of time, and so many pains and headaches every day.

Ha. Try Clojurescript. You'll be surprised.

Re: TypeScript 3.7

#82

Earlier quoted context omitted.

I’ve run into the exact same situation and continue to repeatedly. In fact this is a stupidly common pattern in a library in working on at work right now. My solutions have involved casts (and comments explaining the assumptions involved) instead of the ‘if’ statement more times than I’d like to have done, but it ends up with the same result with the added (however small) compute with the conditional since it can be…

Its unnecessary until the clause above it changes and the assumption no longer holds. That's how I fight my urge to go with the cast.

That’s totally fair. Admittedly in my situation I have high degree of control over the input so my constraints are probably a little looser.

At any rate, I’d appreciate the same thing you would in these cases.

Re: TypeScript 3.7

#83

Earlier quoted context omitted.

It's nice for situations where you want to access a deeply nested prop, and you only care whether the whole path is there or not. Saves you having to add a seperate check for every level of the hierarchy. e.g. You can do: foo?.bar?.baz || "default"; Rather than: (foo && foo.bar && foo.bar.baz) || "default"; Agree that developers can be careful about nullability (in fact I pulled someone up on this in a code review ea…

Shouldn't that be foo?.bar?.baz ?? "default"

Sure. It's a before and after where the after is both easier to write and more correct.

Re: TypeScript 3.7

#84
post #52

I really like the optional chaining operator for statically typed languages. Especially in TypeScript where you have the nullabilaty information baked into the type system. However, in JS itself, it might cause developers to lose track of what can be null/undefined in their code. In case they start to "fix" stuff by throwing in some "?." because they don't know better, the code maintainability will degrade a lot. May…

I agree, I’m dreading the question mark in my codebase. Everyone is just going to start throwing it everywhere and you’ll never be able to reason about what exists and what doesn’t.

If something is null or undefined, you should deal with it in one place, the correct place. And downstream code should be able to assume all data exists.

Re: TypeScript 3.7

#85

I'm a big fan of the new operators. One of my remaining gripes with Javascript/Typescript is the try/catch mess around await. It makes assignment of const a pain for async calls that may reject. e.g. let result: SomeType; try { result = await funcThatReturnSomeType(); } catch (err) { doSomethingWithErr(err); } // at this point result is `SomeType | undefined` if (result) { doSomething(result); } I really want some ki…

IIFEs are an option:

    const result = await (() => {
      try {
        return funcThatReturnSomeType();
      } catch (err) {
        doSomethingWithErr(err);
      }
    })();

Re: TypeScript 3.7

#86
post #67

I just did some refactoring on a medium size code base and here are a few things to watch out for when adopting optional chaining and the new null coalescing operator: foo && await foo(); is not the same as await foo?.(); this will work in most cases but subtly, the await wraps the undefined case into a Promise, while the original code would skip the await altogether. String regular expression matching returns null,…

You have to watch out for first and last one in JavaScript but not on TypeScript as it isn't possible to make that mistake because you have to type it as a promise or in the last one as void.

You can even avoid the problem in the second one by using NonNullable TypeScript types, but I admit that's not common so its still likely to arise.

Re: TypeScript 3.7

#87

Earlier quoted context omitted.

Definitely. It's a shame that dart gets so much unwarranted hate. I mean, I also think it's an absolutely awful language but it's really proven to be a valuable source of data for what other programming languages should do and perhaps more importantly: not do. I really hope we see a lot more things like Dart, and not so much negativity.

Depending on when you last looked at Dart, there's a good chance we've either fixed or are fixing the things you hate about it. What didn't you like?

> What didn't you like?

That the suggested features in this open issue [1] can't be implemented soon enough :)

Is there a roadmap available that would give an idea as to when x, y, z language features may be implemented?

[1] https://github.com/dart-lang/language/issues/546

Re: TypeScript 3.7

#88
post #17

Earlier quoted context omitted.

>Just be sure to not be too strict in your tsconfig.json in the beginning. Do you mean to avoid using the "strict" rule, or are you referring to other rules? My number one Typescript suggestion is to make sure you start with "strict": true in your tsconfig.json to be sure your code has nullability correctly enforced.

I'm talking about "noImplicitAny", "noImplicitReturns", "noImplicitThis"... they get in my way when I'm editing. When I'm about to push my code I activate them back.

Personally I just don’t block the result of my hot dev server on the type checking.

I follow along with types in my IDE, and in a separate command.

Basically Babel for transpilation (which strips all types, correct or not), and type checking in a separate process.

Re: TypeScript 3.7

#89

I'm a big fan of the new operators. One of my remaining gripes with Javascript/Typescript is the try/catch mess around await. It makes assignment of const a pain for async calls that may reject. e.g. let result: SomeType; try { result = await funcThatReturnSomeType(); } catch (err) { doSomethingWithErr(err); } // at this point result is `SomeType | undefined` if (result) { doSomething(result); } I really want some ki…

You are unnecessarily wrapping it into Maybe. Promise.then/.catch is essentially what you want.

Re: TypeScript 3.7

#90

I'm a big fan of the new operators. One of my remaining gripes with Javascript/Typescript is the try/catch mess around await. It makes assignment of const a pain for async calls that may reject. e.g. let result: SomeType; try { result = await funcThatReturnSomeType(); } catch (err) { doSomethingWithErr(err); } // at this point result is `SomeType | undefined` if (result) { doSomething(result); } I really want some ki…

I use await-to-js[1] to clean this stuff up. You can pair it with destructuring arrays like so:

const [err, result] = await to(funcThatReturnSomeType());

if(err) doSomethingWithErr(err);

doSomething(result);

[1] https://www.npmjs.com/package/await-to-js

Post reply on HN