Announcing: A Free Book, A New Course, A Huge Price Cut...
It's a massive ship day. We're launching a free TypeScript book, new course, giveaway, price cut, and sale.
You have likely been sent this article because you asked someone a TypeScript question without providing a TypeScript playground.
Here's how to fix it.
Go to the TypeScript Playground.
Write your code in the editor. You can use libraries from npm
(by simply importing them) if needed.
If your code doesn't fit in the editor, make your example simpler and smaller. The less code you ask someone to read, the more likely they are to help you.
Make sure you comment your code to show what you expect to happen.
// `a` should be inferred as a string, but it's a number...
const a = 1;
Consider using @ts-expect-error
to show where errors are expected in your code.
Make sure your code has NO errors except for the ones you expect to be there.
Save the playground. This will provide you with a URL that you can share with others.
If you asked the question on a platform that doesn't support sharing links (like YouTube comments), head to my Discord Channel to ask it.
If you provided a screenshot to illustrate your problem, you might be over-estimating the skill of the developers you're asking for help.
Most developers can't just look at a screenshot and know exactly what the error is. They need to play with code in order to understand what it does. For this, you need an IDE.
This is why the TypeScript playground is so useful - it provides shareable playgrounds that help facilitate collaboration.
There are several tools out there that help provide a multi-file IDE with support for actually running code.
These are great for sharing code, but they're not great for asking questions.
I've had many situations where people ask me a question using a StackBlitz/CodeSandbox link, and I have to spend 10 minutes trying to figure out what the problem is, or even in which file it originates from.
So, I've learned to dread these links.
The TypeScript playground is a much better tool for asking questions, because it provides a single file with a single entry point.
Share this article with your friends
It's a massive ship day. We're launching a free TypeScript book, new course, giveaway, price cut, and sale.
Learn why the order you specify object properties in TypeScript matters and how it can affect type inference in your functions.
Learn how to use corepack
to configure package managers in Node.js projects, ensuring you always use the correct one.
Learn how to strongly type process.env in TypeScript by either augmenting global type or validating it at runtime with t3-env.
Discover when it's appropriate to use TypeScript's any
type despite its risks. Learn about legitimate cases where any
is necessary.
Learn why TypeScript's types don't exist at runtime. Discover how TypeScript compiles down to JavaScript and how it differs from other strongly-typed languages.