Matt Pocock Profile picture
I teach devs for a living. Author of Total TypeScript and AI Hero. Ex-@vercel. Used to be a voice coach.
6 subscribers
Apr 9 5 tweets 2 min read
I've just been reading the Agent2Agent technical docs - Google's new protocol for agent to agent communication.

You know what that means. Let's diagram them: Image Agents can be discovered by a public 'card' they expose via http. Image
Apr 9 8 tweets 2 min read
Some notes on Cursor vs VSCode's new agent mode: I'm currently working on a course where each lesson is a prompt, and you build a complex application from ~50 prompts.

This gives me a pretty gnarly eval for testing agent mode.

I've been using Cursor to build the course, but I tried VSCode instead.

How did it do?
Mar 25 7 tweets 1 min read
Ohhhhhh I think I've found an AI writing flow I'm happy with

Need to iterate on it before I write about it more, but it's really working. Essentials are:

1. Create a big multi-step plan for the article, including checkboxes. On the current article I'm working on, it's 16+ steps.
2. For each step, ask it for 3 different plans for how to write the section. Give the section a target word count.
Mar 7 7 tweets 2 min read
MCP has ALREADY become an overloaded term.

Let's break it down into clients, servers and protocols: Image MCP is built out of three ideas.

You have a client, a server, and a protocol to connect them together. Let's define each of them in turn.
Mar 6 6 tweets 2 min read
Lots of folks feeling FOMO about MCP.

Here's the problem it solves: Image
Image
If you want to get your LLM to do useful things in the world, you will quickly hit a problem.

All the useful things in the world, like Slack, GitHub, or even your local filesystem, provide their own unique API to access them.
Oct 1, 2024 7 tweets 2 min read
z.strict() fixed a nasty bug for me this morning.

You should probably be using it on most of the schemas that handle outside data.

Here's the bug 🧵 Image I had a form where I was marking the date a post was posted. I was expecting a key of `postedAt`, with an optional datetime. Image
Aug 20, 2024 13 tweets 3 min read
Narrowing down the types of values is key knowledge for any TypeScript dev.

Here's 11 different ways you can do it. I bet you won't know 2 or 3 of them!

🧵 Narrowing with typeof: Image
Aug 8, 2024 10 tweets 3 min read
So many folks don't know about structuredClone.

It's awesome, built-in, and supported in all major browsers.

Let's learn 🧵 Image A common pattern in JavaScript is to create an immutable clone of an object. This is useful when you want to make mutations to it without changing the original.

For that, you'll often see code using the spread operator: `{ ...obj }`. Image
Aug 7, 2024 4 tweets 1 min read
I'm starting to think that library types in TypeScript are all wrong.

Instead of top-level types, they should be available right on the functions that use them.

Brief thread 🧵 Image How is this possible? Well, it's due to a trick in the way namespaces work in TypeScript.

When you export a namespace with the same name as a function, TypeScript combines the two: Image
Aug 5, 2024 11 tweets 4 min read
I've changed my mind on .d.ts files.

If you're writing application code, you should NEVER use them.

Let me explain 🧵 Declaration files are files that only contain types.

They've got two purposes - providing types for JavaScript files, and augmenting types in the global scope.

Here's the section on them in my book:

buff.ly/3SDoL6p
Aug 5, 2024 7 tweets 3 min read
Sometimes, TypeScript's narrowing kind of sucks.

The prime suspect? Boolean.

Let's take a look at why. 🧵 Image Let's explain the code above. `myFunc` takes in a string or null. We want to ensure it's not null for some reason.

So, we can use an if statement to check if it's truthy. If it's truthy, it ain't null.

We can do that in MANY different ways: Image
Jul 9, 2024 12 tweets 4 min read
In celebration of my free book coming out, here's a massive thread of all my best free TypeScript resources.

I guarantee that if you work through this list, you'll be the top TypeScript wizard at your company.

🧵 We've got to start with the book. It's 16 chapters of totally free written content.

It goes from first principles all the way up to the bottom end of advanced.

It's the no-brainer place to start.

totaltypescript.com/books/total-ty…
Oct 24, 2023 6 tweets 3 min read
After all the chat about typing event handlers in React, I figured I'd write down all the suggestions folks gave.

Quick 🧵 Image The most popular solution is to hover the onChange attribute in the JSX, then use that to type your handler.

But this creates an astonishingly long type - very intimidating for newbies.
Image
Image
Sep 4, 2023 4 tweets 2 min read
How should you type React Props?

You've got three options. type, interface or an inline object literal.

Inline object literals might be fast to write, but it means you can't extract the type out for use elsewhere in your codebase:
This makes them hard to recommend.

So, interface vs type again. As I've said before, I prefer type.

But let's say you're building an input that needs to take all the props of 'input', but with an extra label.

For those cases, you must use interfaces:
Using an intersection here will slow down TypeScript on the scale of a large codebase. interface extends is the way to go.

This means that it's a good idea to get into the habit of using interfaces for each prop declaration.

I recommend using a code snippet to declare the interface for you:
All the speed of an object literal, but all the reusability and TS performance of an interface.

Want to share outside of X? Head to Total TypeScript:

totaltypescript.com/react-props-ty…
Jul 20, 2023 18 tweets 5 min read
If you don't understand generics in TypeScript, I think there's something you've misunderstood.

There is no such thing as a 'generic'.

🧵 Image There are generic types, generic functions, and generic classes.

There are type arguments, and type parameters.

You cannot 'pass' a generic, 'declare' it, or 'infer' it.

In other words, 'generic' is not a noun, it's an adjective.

totaltypescript.com/no-such-thing-…
Mar 7, 2023 5 tweets 1 min read
Lazy Dev Twitter:

Anyone know if it's possible to detect a QR code (or even just a fiducial) from a video using ffmpeg? I'm asking for a slightly hilarious reason.

I use ffmpeg for automatically editing my videos. When I screw up a take, I want to be able to hold up a QR code on a paddle to tell my editing software to discard that take.
Mar 6, 2023 20 tweets 7 min read
Why any's happen, how to stop them, and why unknown isn't necessarily a better solution 🧵

Any 'any' in a codebase is a cause for concern. That's because it disables typechecking on the thing it's assigned to.

Pass it to a function parameter? You then can't guarantee anything about that function parameter. const groupBy = (arr: any[], key: any) => {   const result:
Mar 3, 2023 5 tweets 2 min read
Working with mocks in TS sucks.

The only way you can make it work is by slapping 'as' on everything - which can make the tests hard to maintain.

What if you had a simple set of functions that could let you pass whatever you wanted, but with perfect autocomplete? import { partial, any } from "@total-typescript/mock-ut This feels pretty simple on the surface - many of you might have tried to make these kinds of abstractions before.

But it's harder than you think - you need a bit of wizardry. Let's take partial().

Why isn't the code below working? const partial = <T>(mock: Partial<T>): T => {   return mock
Mar 2, 2023 18 tweets 6 min read
satisfies in TypeScript has been out for a little while now.

Overall, it's been a success - but it's starting to cause some confusion.

Let's clear it up. const obj = {} satisfies Record<string, string>;  // Propert satisfies has added yet another tool to the TypeScript user's toolkit.

There are now _three_ ways to assign types to values.

Mar 1, 2023 10 tweets 2 min read
Today's the day.

Total TypeScript is ready. Your Total TypeScript adventure starts now 🧙 Hundreds of videos over three modules
🔥 The deepest exploration of Generics on the market
❤️ Interactive editors, transcripts, and thousands of words of accompanying articles
🪄 Perfect if you've used TS for a while, but want to achieve mastery

totaltypescript.com
Feb 20, 2023 12 tweets 5 min read
TypeScript annoys me sometimes.

So, I decided to do something about it... const arr = [1, 2, 3, undefined];  const result = arr.filter It's always bugged me that JSON.parse returns 'any'.

It means that, just by using an extremely common JS method, you're introducing a dangerous type into your codebase. // REAL LIFE  const result = JSON.parse("{}");  co