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.
TypeScript 3.7
81–90 of 167 posts
Re: TypeScript 3.7
#82Earlier 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.
At any rate, I’d appreciate the same thing you would in these cases.
Re: TypeScript 3.7
#83Earlier 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"
Re: TypeScript 3.7
#84I 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…
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
#85I'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…
const result = await (() => {
try {
return funcThatReturnSomeType();
} catch (err) {
doSomethingWithErr(err);
}
})();Re: TypeScript 3.7
#86I 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 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
#87Earlier 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?
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?
Re: TypeScript 3.7
#88Earlier 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.
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
#89I'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…
Re: TypeScript 3.7
#90I'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…
const [err, result] = await to(funcThatReturnSomeType());
if(err) doSomethingWithErr(err);
doSomething(result);