Work through questions on narrowing, generics and React props. When a live interview moves from a type error to a follow-up, send Hiintly the spoken question or a screenshot of the editor for a suggested explanation or code change.
A technical screen may ask you to read a snippet and predict which operations the compiler accepts. A shared editor round may start with a function signature and add a new caller or input. In a project discussion, you might explain why you changed an API type. Start with the format the recruiter described and practice separating what the compiler can prove from what the program checks.
When should you use unknown instead of any?
Use unknown for input you haven’t checked. With any, you could call value.trim() without the compiler objecting, even if the value is a number. With unknown, first check typeof value === 'string'. Inside that branch, TypeScript knows that trim() is available.
Follow-up: If the input is an object with a nested string, checking typeof value === 'object' is just the first step. Exclude null and check the nested value before using it. The TypeScript Handbook’s narrowing guide explains how these checks affect what the compiler knows.
Why use a discriminated union instead of optional fields?
With { status, url?, message? }, the type can allow a ready result with no URL. Give each status its own object type and require the fields that go with it. Once result.status === 'ready', TypeScript knows that result.url is a string.
Follow-up: What if a new status has no URL? Add a separate union member and give that state its own rendering path. Avoid making the ready state weaker just to accommodate a different state.
When would you choose an interface over a type alias?
Either can describe an object shape. Reach for a type alias to name a union or a tuple. Use an interface when declaration merging is an intended feature, such as an extension point for plugins. A type alias cannot be reopened by declaring the same name again.
Follow-up: Can two objects with different named types still be compatible? Often yes. For ordinary object shapes, TypeScript compares their required members. Giving two otherwise identical shapes different names does not prevent one from being assigned to the other.
What’s the difference between an optional field and string | undefined?
label?: string lets a caller omit the key. label: string | undefined still requires the key, even when its value is undefined. With exactOptionalPropertyTypes, an optional string field does not accept an explicitly assigned undefined unless the value type includes it.
Follow-up: Why does presence matter? When applying a patch with object spread, an omitted key leaves the old label alone. A present key with value undefined overwrites it.
For a spoken follow-up, submit the question from the Hiintly transcript with the relevant compiler option or code. For example: “Assume exactOptionalPropertyTypes is on. Explain why omitting the field compiles but passing undefined doesn’t.” For questions about promises or closures at runtime, see the JavaScript interview guide.
TypeScript coding exercise: validate an export result
An API responds with either a ready export and its URL, or a failed export and a message. The interviewer asks you to accept unknown input, reject malformed values and return a result that the rest of the app can use safely. Assume TypeScript 4.9 or later and strict mode. The task requires string fields; it does not require parsing the URL or rejecting empty strings.
Validate before assigning a type
type JobResult =
| { status: 'ready'; url: string }
| { status: 'failed'; message: string };
function decodeResult(input: unknown): JobResult {
if (typeof input !== 'object' || input === null) {
throw new Error('Expected an object');
}
if ('status' in input) {
if (input.status === 'ready' && 'url' in input &&
typeof input.url === 'string') {
return { status: 'ready', url: input.url };
}
if (input.status === 'failed' && 'message' in input &&
typeof input.message === 'string') {
return { status: 'failed', message: input.message };
}
}
throw new Error('Invalid job result');
}
Explain where the guarantees come from
An assertion such as raw as JobResult would silence the compiler without checking the response. The decoder checks the object and the fields for each status, then constructs the corresponding union member. A well-formed failed response is a valid result. A malformed response throws because it doesn’t match the contract.
{ status: 'ready', url: '/exports/a.csv' }
A ready result. The caller can read url after checking status.
{ status: 'failed', message: '' }
A valid failure result. The contract accepts an empty message.
{ status: 'ready', url: 42 }
Rejected. The status matches, but the payload has the wrong type.
null
Rejected before checking any properties.
If the caller should keep rendering after bad input, return a separate parse outcome such as { ok: false, error } instead of throwing. Keep that outcome distinct from a valid response saying the export job failed.
Follow-up: “The export can now be pending.”
Add { status: 'pending'; jobId: string } to JobResult, and add a decoder branch that accepts pending only when jobId is a string. In resultText, TypeScript now flags assertNever(result) because the pending member can still reach it. Add a pending case to display its job ID. The compiler catches the missing rendering case; a test using a pending response catches a forgotten decoder branch.
Capture the original function with Hiintly and type the new requirement: “Pending has a string jobId and no URL. Show the changes to the union, decoder and switch. Include a pending payload that should fail validation.” That gives Hiintly the contract the screenshot alone can’t show.
function assertNever(_value: never): never {
throw new Error('Unhandled job status');
}
function resultText(result: JobResult): string {
switch (result.status) {
case 'ready':
return 'File ready: ' + result.url;
case 'failed':
return 'Export failed: ' + result.message;
default:
return assertNever(result);
}
}
Advanced TypeScript question: how do you keep a return type precise?
“Write a property reader that accepts only valid keys and returns the type of the chosen property.” Using keyof T for a single parameter restricts the allowed keys, but a return type of T[keyof T] combines all possible property types. Add a type parameter K constrained to keyof T and return T[K] to retain the relationship. See the TypeScript Handbook’s section on generic constraints.
If the interviewer changes the key to 'id' | 'attempts', the result becomes string | number. If a user types the key and all you have is a string, first check it against the allowed keys. A cast would hide an invalid lookup rather than prevent it. In a project discussion, explain where a generic helper preserved information for callers and when direct access was clearer.
function read<T, K extends keyof T>(
record: T, key: K,
): T[K] {
return record[key];
}
const job = { id: 'job-3', attempts: 2 };
read(job, 'id'); // string
read(job, 'attempts'); // number
// read(job, 'owner'); // type error
React TypeScript interview questions: design the props first
In a frontend round, the interviewer may ask you to review a component contract before writing the markup. A download control should render a link if a file already exists and a button if the user must request an export. How do you stop a caller from giving it both an href and an onClick?
type DownloadActionProps =
| { kind: 'link'; href: string; onClick?: never }
| { kind: 'button'; onClick: () => void; href?: never };
function DownloadAction(props: DownloadActionProps) {
if (props.kind === 'link') {
return <a href={props.href}>Download</a>;
}
return (
<button type="button" onClick={props.onClick}>
Generate export
</button>
);
}
Answer with a caller the type should reject
With two ordinary optional props, a caller could supply both or neither. Model each variant with its required prop and use optional never for the prop it shouldn’t receive. A kind: 'link' caller that also supplies a click callback is now rejected. Inside the component, the same kind check gives you the right props for the chosen element.
Follow-up: If both variants need a label, add label: string as a shared prop. If only the button can be disabled while an export is running, keep that field on the button variant. The type should reflect where the behavior actually exists.
If the interviewer shows a failing call site, capture the usage and the props declaration with Hiintly. Ask which requirement the caller violates before asking for a code change. For a round that also covers rendering, state and accessibility, see the frontend developer interview guide.
Set up Hiintly for your TypeScript interview
Give Hiintly the compiler and role context
Choose Coding Interview and use Extra Instructions to specify TypeScript, the version and any known compiler options. If the round includes a project discussion, add your resume, the job description and the part of the TypeScript work you can speak to.
Send the question with the relevant code
Send the spoken question from the transcript, or capture the error and its call site from the selected screen source. Add missing context in a typed message: “The value came from JSON. Explain the runtime checks before suggesting a type.”
Check the suggestion in your editor
Read the inferred type and try both a valid and a malformed input. If the interviewer changes the contract, send the new constraint and ask which part of the code needs to change. The coding interview copilot guide walks through this workflow for a broader coding round.
What TypeScript interview questions should I prepare for first?
Practice explaining unknown versus any, narrowing a union and reading an inferred type. Then solve a small task where the input can be invalid. Be ready to name the runtime check, the resulting TypeScript type and what the caller can safely do next.
Do I still need JavaScript for a TypeScript interview?
Yes. TypeScript types do not change how JavaScript handles promises, mutations or property lookup. A coding round can test both layers: first explain what a function does at runtime, then show what its signature promises to callers.
What might a senior TypeScript interview ask beyond syntax?
You might be asked how to evolve a public type without breaking callers, how to validate an upstream response or when a generic abstraction makes a library harder to use. Bring a real example and explain how you checked compatibility or caught invalid input during the change.
Does the TypeScript version or tsconfig matter in a coding interview?
Yes. Ask which compiler version and options the editor uses. For example, noUncheckedIndexedAccess adds undefined to reads of undeclared indexed fields. The decoder on this page uses TypeScript 4.9 or newer for narrowing properties on an object when checked with in.
Can I try Hiintly on a TypeScript question for free?
Yes. Start a free 10-minute session without a credit card. Send a snippet or a spoken question, then change a constraint to see how the suggestion changes. You can start another free session after the cooldown.