Will it compile puzzles
Twelve type puzzles with real compiler diagnostics.
Twelve puzzles, same rules as interviews: read, commit to Yes or No (and the failing line), then reveal the real diagnostics. Every reveal shows what the pinned compiler actually reported — the machine grades you, not your confidence.
Puzzle 1: extra property — decide first, then reveal.
interface Account {
id: number;
name: string;
}
const account: Account = { id: 1, name: "sam", nickname: "s" };
console.log(account);Puzzle 2: guarded length — decide first, then reveal.
function shout(text: string | null): string {
if (text === null) {
return "";
}
return text.toUpperCase();
}
console.log(shout("hi"));Puzzle 3: frozen list — decide first, then reveal.
const scores: readonly number[] = [10, 20];
scores.push(30);
console.log(scores);Puzzle 4: union into number — decide first, then reveal.
const mixed: string | number = "a";
const exact: number = mixed;
console.log(exact);Puzzle 5: inferred identity — decide first, then reveal.
function identity<T>(value: T): T {
return value;
}
const word: string = identity("hello");
console.log(word);Puzzle 6: dictionary values — decide first, then reveal.
interface Scores {
[player: string]: number;
}
const table: Scores = { sam: 3, jo: "many" };
console.log(table);Puzzle 7: leaking any — decide first, then reveal.
const payload: any = { count: "three" };
const count: number = payload.count;
console.log(count);Puzzle 8: throwing helper — decide first, then reveal.
function fail(message: string): never {
throw new Error(message);
}
const name: string = fail("boom");
console.log(name);Puzzle 9: missing argument — decide first, then reveal.
function greet(name?: string): string {
return name;
}
console.log(greet());Puzzle 10: claimed string — decide first, then reveal.
const raw: unknown = "preview";
const text: string = raw as string;
console.log(text);Puzzle 11: tuple push — decide first, then reveal.
const pair: [string, number] = ["a", 1];
pair.push(2);
console.log(pair);Puzzle 12: plain index — decide first, then reveal.
const names: string[] = ["sam", "jo"];
const first: string = names[0];
console.log(first);