This Crazy Syntax Lets You Get An Array Element's Type
Learn how to extract the type of an array element in TypeScript using the powerful Array[number]
trick.
Cannot use JSX unless the '--jsx' flag is provided.
This error is likely happening because you haven't specified jsx
in the compilerOptions
of your tsconfig.json
.
{
"compilerOptions": {
"jsx": "react"
}
}
This option tells TypeScript that you're using JSX - the syntax that many frontend frameworks use to render elements.
jsx
?There are several possible values you might need to consider for jsx
. You can refer to my article solving the 'React refers to a UMD global' error for more information.
The most likely values to work are:
preserve
: preserves the JSX as it is and doesn't add any extra transformations.react-jsx
: uses a modern transform (_jsx
) that works with React 17 and above.react
: uses a legacy transform (React.createElement
) that works with React 16 and below.Try those in order, and see which one works for you.
And if you want to learn React and TypeScript more fully, check out my free React and TypeScript beginner's course. There are 21 interactive exercises packed with TypeScript tips and tricks for React apps.
Explained: Cannot use JSX unless the '--jsx' flag is provided
Learn how to extract the type of an array element in TypeScript using the powerful Array[number]
trick.
Learn how to publish a package to npm with a complete setup including, TypeScript, Prettier, Vitest, GitHub Actions, and versioning with Changesets.
Enums in TypeScript can be confusing, with differences between numeric and string enums causing unexpected behaviors.
Is TypeScript just a linter? No, but yes.
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.