TypeScript

cross-posted from: https://lemmygrad.ml/post/987224 > I came up with a trick to iterate over string union types (kind of). I don't know if anyone has discovered this independently, but I think it's too useful not to share. > > You can do it with a pattern like this: > ```typescript > const values = ['foo', 'bar', 'baz'] as const; > > type Value = (typeof values)[number]; > ``` > > Let's break down what is going on here. `values` is a list of strings, however the `as const` makes it so that Typescript treats it as a tuple of string literals instead of just `string[]`. When defining `Value`, we use that tuple type to get the type of what you would get by indexing the tuple with a number. Since that type could be any of the string literals in the tuple, the resulting type is a union of all the literals in the tuple, i.e. `'foo' | 'bar' | 'baz'`. This makes it so you can use `Value` as the union type, and if you ever want to iterate over all the values of the union, you can do that with `values`. This should allow you to do the one thing that Typescript's crappy enums has over string unions. > > You can see this technique in action in the [bot library I made](https://github.com/SleeplessOne1917/lemmy-bot/blob/main/src/db.ts).

9
0
devblogs.microsoft.com

For me, the biggest excitement is around "Easier Implicit Returns for undefined-Returning Functions". It's nice not to have to insert a `return undefined;` when that's the implicit behavior.

2
0
https://blog.coderspirit.xyz/blog/2022/12/08/animated-gosper-curve-in-ts/

cross-posted from: https://lemmy.ml/post/642690 > An introductory article on how to leverage some basic mathematical tricks and widely available browser APIs to generate beautiful animations.

1
0
devblogs.microsoft.com

Here’s a quick list of what’s new in TypeScript 4.9! - The satisfies Operator - Unlisted Property Narrowing with the in Operator - Auto-Accessors in Classes - Checks For Equality on NaN - File-Watching Now Uses File System Events - "Remove Unused Imports" and "Sort Imports" Commands for Editors - Go-to-Definition on return Keywords - Performance Improvements - Correctness Fixes and Breaking Changes

1
0
https://blog.coderspirit.xyz/blog/2022/11/06/export-barrels-considered-harmful/

My (probably controversial) take on why the barrel exports pattern can be harmful.

1
0
deno.com

One of the great advantages of Deno is the absence of a package manager, this section is practically monopolized by two corporations (MS with npm and FB with yarn); Deno has shown itself to be a more independent ecosystem with respect to its counterpart, Node. Do you think that this decision taken by the core team was the right one? would you have preferred it to become a foundation instead of a company? Will it become a more independent solution or will it end up like Node with OpenJS? being a front entity for a few big techs that lobby the ecosystem?

1
0
github.com

#### Why? > Why not? I mean - I think there is genuine utility, but even if there wasn't, it would simply be an interesting project to undertake.

1
0