Code2Img

TypeScript code screenshots.

How to screenshot TypeScript code properly: what TypeScript snippets actually look like, how auto-detection behaves, the theme that reads best, and the settings that keep the card legible.

What people actually paste

TypeScript snippets are the densest of the ten: an interface with optional members, a generic constraint (<T extends Record<string, unknown>>), a discriminated union, and a satisfies clause can all land in the same 20 lines. The characteristic shape is type annotations inside value code — const handler = async (req: Request): Promise<Response> => { — so a renderer that colourises identifiers and strings but flattens types produces a card where the part that matters (the types) is invisible. Expect long lines too: z.infer<typeof schema>[] and union literals push past 100 columns quickly, which collides with the width clamp.

How auto-detection behaves

TypeScript is rule 14, and rule 13 (JavaScript) fires on const, let, console., =>{, or any line starting with a brace. Since nearly every TS snippet contains a const or an arrow function, auto-landing on javascript is the normal case, not the exception. You get typescript automatically only when nothing earlier matches — an interface/type declaration at line start, a : string | number | boolean annotation, or import type. In practice: paste an interface alone and it guesses right; paste the implementation and the annotations lose their colour. One extra trap: function load(x: string) { matches the PHP rule (9) before either JS or TS, because function followed by a name and a paren is the PHP signature.

Theme that reads best

vitesse-light is the strongest light pick here: its palette keeps type annotations one step quieter than keywords, so an interface body reads as structure rather than as a wall of colour. For dark cards vitesse-dark behaves the same way, and github-dark is the safe alternative if the card goes into a README that already uses GitHub's palette.

Three tips

Other languages

The same advice, for the languages people paste most.

How Code2Img compares

Feature by feature, against the other code screenshot tools.