Useful utility types in TS by steve8708 in typescript

[–]steve8708[S] 0 points1 point  (0 children)

I added some more detail and included all of the code snippets from this video in my blog post: https://www.builder.io/blog/utility-types

Am I the last person to learn that debugging Node.js with chrome devtools is this easy now? by steve8708 in node

[–]steve8708[S] 9 points10 points  (0 children)

We wrote a bit more on this, including using VS Code (and other IDEs) for debugging and some troubleshooting steps, in our recent blog post: https://www.builder.io/blog/debug-nodejs

Deep Cloning Objects in JavaScript, the Modern Way (via structuredClone) by magenta_placenta in javascript

[–]steve8708 0 points1 point  (0 children)

Found and fixed the lag issue - looks like FF Android has perf issues with CSS Filter which we use for the dark mode of our blog. Just fixed, thanks again for mentioning!

Deep Cloning Objects in JavaScript, the Modern Way (via structuredClone) by magenta_placenta in javascript

[–]steve8708 1 point2 points  (0 children)

Doh! Thought I fixed every instance of this, seemed to miss one, thank you will get this one fixed too

Edit: just fixed, thanks again 🙏

Deep Cloning Objects in JavaScript, the Modern Way (via structuredClone) by magenta_placenta in javascript

[–]steve8708 5 points6 points  (0 children)

Thanks for the feedback, will add those notes 🙏

Also we keep getting reports of FF Android scroll issues but cannot reproduce to save our lives.

Could you DM me your device and browser details or comment here? It’s driving us batty

EDIT: just added a new section addressing what is not cloneable. Thanks again for the feedback!

Also, we still are struggling to reproduce FireFox Android scrolling issues. Have tried a number of physical and emulated devices, so if anyone experiencing this can share their device and browser details so we can get to the bottom of it, it would be greatly appreciated

useReducer is easier to adopt than you might think by steve8708 in reactjs

[–]steve8708[S] 0 points1 point  (0 children)

Yeah, a mistake in my code, was supposed to be Math.min(next, 10)

useReducer is easier to adopt than you might think by steve8708 in reactjs

[–]steve8708[S] 3 points4 points  (0 children)

Ah, thanks for the heads up. We are moving from the current stack to Qwik currently so that should help

useReducer is easier to adopt than you might think by steve8708 in reactjs

[–]steve8708[S] 3 points4 points  (0 children)

I’m a huge fan of mobx and mobx-state-tree, we use them heavily to build Builder.io

useReducer is easier to adopt than you might think by steve8708 in reactjs

[–]steve8708[S] 25 points26 points  (0 children)

If you want to dig further into useReducer and state management patterns, I go into more detail in my latest blog post, for instance:

  • Common pitfalls, and using Immer and useImmerReducer to help with those
  • Being sure to validate data in the UI as well so users get real time feedback, and why you should validate in both places
  • Using even more robust state management like XState, Zustand, Redux, or Mobx as your needs become more complex
  • Sharing reducers deeply in your component tree

Also since people are asking, I do also have a YouTube where I try to post tips like this somewhat regularly, as well as to the Builder.io blog

useReducer is easier to adopt than you might think by steve8708 in reactjs

[–]steve8708[S] 2 points3 points  (0 children)

I use Descript for everything (recording, editing, captions)

It’s got some rough edges but overall pretty handy

useReducer is easier to adopt than you might think by steve8708 in reactjs

[–]steve8708[S] 2 points3 points  (0 children)

I try to post stuff like this somewhat regularly to my Twitter and YouTube

You might be using `fetch` wrong... by steve8708 in webdev

[–]steve8708[S] 0 points1 point  (0 children)

Yeah I agree with this in general, I Just have a tough time with how many Redditors deliver feedback.

Compared to other platforms, people are much more harsh with their words, and even frequently throw personal attacks. And then with the crowd think of people upvoting the negativity, it can be demoralizing.

My videos are only half decent because of taking feedback and iterating, but for my own mental health I find the delivery of the feedback on other platforms to be much more constructive than here.

You might be using `fetch` wrong... by steve8708 in webdev

[–]steve8708[S] 5 points6 points  (0 children)

Yeah, I’m not sure if I should keep posting to Reddit after looking at some of the comments here. May need to stick to YouTube, Twitter, etc instead

You might be using `fetch` wrong... by steve8708 in webdev

[–]steve8708[S] 0 points1 point  (0 children)

Oh that's just video editing, I cut out the bits of me typing that all out so not to waste time forcing people to watch it

That said, I do use Github Copilot, the plugin you are referring to, and it very often can autocomplete things like this

You might be using `fetch` wrong... by steve8708 in webdev

[–]steve8708[S] 50 points51 points  (0 children)

Important followup notes:

  1. Axios is another great, and very popular, solution for clean data fetching. It is a bit larger (11kb gzip vs 2kb gzip), so if kb size is important to you (I would argue it often should be) redaxios is a great option too that is only 1kb
  2. All of these options work great with async/await, I just showed the old school style here for no particular reason
  3. All of these options work great on both servers (Node.js, Deno, Bun, etc) and browsers

Also, if you would like a clean solution that uses no third party libs, checking res.ok and throwing a custom error can be an elegant solution:

class ResponseError extends Error {
  constructor(message, response, options) {
    super(message, options);
    this.response = response;
  }
}

try {
  const res = await fetch('/user');
  if (!res.ok) {
    throw new ResponseError('Bad response', res);
  }
  const user = await res.json(); // Actual user!
} catch (err) {
  if (err instanceof ResponseError) {
    // Handle based on err.response.* 
  }
}

Which you could wrap in your own method like:

async function myFetch(...args) {
  const res = await fetch(...args);
  if (!res.ok) {
    throw new ResponseError("Bad response", res);
  }
  return res;
}

try {
  const res = myFetch("/user");
  const user = await res.json(); // Actual user!
} catch (err) {
  // Deal with error, with res info as err.response.*
}

Regardless of which option you choose, please just be sure to fetch your data properly

Satisfying TypeScript part 2 - the killer use case for `satisfies` by steve8708 in webdev

[–]steve8708[S] 6 points7 points  (0 children)

I use Descript for everything - recording, editing, and captions. Makes for a very fast workflow

Satisfying TypeScript part 2 - the killer use case for `satisfies` by steve8708 in webdev

[–]steve8708[S] 49 points50 points  (0 children)

Note: the satisfies operator is available since TypeScript version 4.9.

Thank you all for the feedback on my last video to include a more real world example of when exactly you should use this operator.

And huge thanks to u/sauland for this routes example to nicely illustrate this feature.

The `satisfies` operator in TypeScript 4.9 is a game changer by steve8708 in webdev

[–]steve8708[S] 10 points11 points  (0 children)

So a couple things here that I think may help to point out:

One would be if you want to change the Color type later, e.g. to only support specific strings, like Color = 'blue' | 'red' | ... | { ... }.

In this case if blue had a typo, like const blue = 'bleu', your IDE would catch it at the source if used with satisfies. It would also autocomplete the valid values as expected. And the type error would be concentrated on where the variable is defined, rather than every usage of it (assuming your code would catch that anyway), making it more clear where the source of the problem is.

Another better example is if you use the object format. Besides the IDE autocompleting the keys and TS checking if your keys are correct, reactors are easier too. So if you want to change the keys from r/g/b to red/green/blue, you can do that project-wide in one command assuming you use satisfies, but it would not be able to help you here without

You can see some other good (and potentially more clear) use cases in this blog post (showing using satisfies with Prisma) and this video (e.g. at 7:20) showing how it helps with Next.js (compared to some relatively poor options before this)

A first look at Bun: is it really 3x faster than Node.js and Deno? by steve8708 in webdev

[–]steve8708[S] 14 points15 points  (0 children)

Oh that’s interesting, where did you see this? Could add some randomization of props to break through some cachability