Type checking
import Avatar from './avatar.tsrx';
export default function Card() @{
<article>
<Avatar size="large" />
</article>
}Avatar takes a size that is a number, and this file passes the string "large". Your editor draws a red line under size: Type 'string' is not assignable to type 'number'.
Type errors show up as squiggles
A squiggle is the red wavy line your editor draws under a mistake, with TypeScript's message on hover. Click an error in the terminal to jump to it, then click the wrong value to fix it:
- Each fix clears its own squiggle.
- Its line leaves the terminal, until only the
passlines remain. - The check runs on every file you open, once your editor is set up.
The check catches real mistakes
These are the messages TypeScript gives in a .tsrx file:
- A prop of the wrong type.
<Avatar size="large" />getsType 'string' is not assignable to type 'number'. - A misspelt name.
{titel}, when the state is calledtitle, getsCannot find name 'titel'. Did you mean 'title'? - A misspelt event handler.
<button onClik={...}>getsProperty 'onClik' does not exist on type '…'. Did you mean 'onClick'?The type it names is long, so it's cut here. - An attribute HTML doesn't have, like
className(writeclass). A camelCase spelling of a real attribute, likestrokeWidthforstroke-width, works too: the build writes the real name. - A handler whose code doesn't type-check.
npm run check checks the whole app
From the next Markless release, npm run check type-checks every .tsrx file too, so CI can run the same check on each pull request:
$ npm run check
pass: All 8 files are correctly formatted (346ms, 18 threads)
pass: Found no warnings or lint errors in 2 files (299ms, 18 threads)
pages/card.tsrx(8,11): error TS2322: Type 'string' is not assignable to type 'number'.
pages/card.tsrx(9,8): error TS2552: Cannot find name 'titel'. Did you mean 'title'?
Each error gives the file, the line and the column. It exits with code 2 until you fix them, then prints only the two pass lines. npm run build still stops only on Markless errors, so a wrong prop builds.
Editor setup turns the check on.