Practise React TypeScript interview questions with typed UI states, controlled props, invalid JSX cases, and tested component behavior in the browser.

Author: PracHub

Published: 11/19/2026

React TypeScript Interview Questions: Model UI States and Catch Invalid Props

November 19, 2026

Quick Overview

Prepare for React TypeScript interview questions with a tested text-field API. Model validation feedback separately from input ownership, reject invalid props and object spreads, and distinguish compiler guarantees from observed React behavior.

Frontend EngineerFree

React TypeScript interview questions become concrete when you design a component that accepts useful combinations of props and rejects misleading ones. Model the UI's meaningful states, make ownership explicit, and verify the public API with both valid JSX and deliberately invalid consumers. Then test what happens when a user actually types.

This guide builds an original text-field exercise around controlled and uncontrolled inputs, validation feedback, and object spreads. Official language and React behavior are cited where introduced. The exercise and interview explanations are preparation advice, not a company's disclosed assessment. Use PracHub's reusable React autocomplete question to extend the same API-design reasoning to a larger component.

React TypeScript field design showing parent-controlled and DOM-owned input values alongside validation feedback

Which UI states should the type actually represent?

Start with the screen's meaning. In this exercise, a field can be idle, checking, valid, or invalid. Invalid feedback requires a message; the other statuses carry no error message. This is an original product policy. A different product could deliberately retain a previous warning during a new validation request.

A discriminated union is a set of object shapes distinguished by a shared property with literal values. Checking that property identifies the relevant shape and its available fields. Here, status connects invalid feedback to the message required to explain it. The TypeScript narrowing handbook documents this mechanism.

Define the feedback separately from input ownership:

export type Validation =
  | { status: "idle" | "checking" | "valid"; message?: never }
  | { status: "invalid"; message: string };

Independent booleans such as isChecking and hasError would allow combinations you have not explained. React's state-structure guidance recommends avoiding contradictory and redundant state. The useful interview answer names which combinations your particular product permits before choosing a type.

Do not add an isInvalid state variable beside this union. Derive that boolean from the current status when rendering. Also explain the remaining limit: a required string can still be empty. Ensuring a useful human-readable message requires validation or a stronger construction boundary.

If the interviewer asks whether checking should disable typing, treat that as another requirement. This exercise permits editing while feedback is being checked; the status does not silently imply a disabled input. A real asynchronous validator would also need a policy for feedback belonging to an older value. Naming that missing behavior is more useful than adding a reassuring type annotation to it.

How do you reject conflicting controlled props?

Ownership answers a different question: who supplies the current input value? For this text field, controlled mode receives a value and a required value-change callback. Uncontrolled mode receives an optional initial default and an optional observation callback. Keeping feedback independent permits either ownership mode to display an error.

Use a second union and combine it with the shared props:

export type Ownership =
  | {
      mode: "controlled";
      value: string;
      onValueChange: (value: string) => void;
      defaultValue?: never;
    }
  | {
      mode: "uncontrolled";
      defaultValue?: string;
      onValueChange?: (value: string) => void;
      value?: never;
    };

export type TextFieldProps = Ownership & {
  id: string;
  label: string;
  validation: Validation;
};

The forbidden properties are intentional. A controlled consumer cannot also provide defaultValue; an uncontrolled consumer cannot provide value. This wrapper deliberately excludes a read-only controlled mode. If the interviewer requires one, add an explicit contract instead of quietly making every callback optional.

Why combine two unions instead of writing one long list of variants? The two ownership choices can each use all four feedback statuses, producing eight meaningful combinations in this exercise. An intersection preserves that independence without repeating the same callback and label fields for each status. If a future product rule couples the decisions, such as a mode that cannot validate, change the model to express that relationship and add a rejected consumer for it.

In the official React input reference, value controls a text input and defaultValue specifies an uncontrolled input's initial value. React also documents the update-handler requirement for editable controlled inputs. The wrapper turns that behavioral distinction into a consumer-facing API.

What should the implementation pass to the DOM?

Branch on the ownership tag and forward the appropriate value prop. Keep application-only fields such as mode and validation off the native input. The following implementation uses the preceding types and needs no React import with the automatic JSX runtime:

export function TextField(props: TextFieldProps) {
  const invalid = props.validation.status === "invalid";
  const errorId = `${props.id}-error`;
  const common = {
    id: props.id,
    "aria-invalid": invalid,
    "aria-describedby": invalid ? errorId : undefined,
  };
  const input = props.mode === "controlled" ? (
    <input
      {...common}
      value={props.value}
      onChange={(event) => props.onValueChange(event.currentTarget.value)}
    />
  ) : (
    <input
      {...common}
      defaultValue={props.defaultValue}
      onChange={(event) => props.onValueChange?.(event.currentTarget.value)}
    />
  );

  return (
    <div>
      <label htmlFor={props.id}>{props.label}</label>
      {input}
      {props.validation.status === "invalid" && (
        <p id={errorId} role="alert">{props.validation.message}</p>
      )}
    </div>
  );
}

The implementation reads the message inside the invalid branch, where the model establishes its presence. The shared DOM props contain only selected native attributes. Both ownership branches preserve the label association and the error description link.

There is no mirrored local value in this wrapper. For controlled usage, the parent supplies the next value after the callback. For uncontrolled usage, the native input retains the edited value. Adding local state to both branches would introduce another owner that the public contract never mentioned.

Should a callback expose an event or a value?

Choose the public abstraction deliberately. This field promises (value: string) => void, so consumers can receive the next text without knowing the native event type. The inline handler adapts the DOM event by reading event.currentTarget.value immediately. React's TypeScript guide explains props and event typing.

A parent can pass a string state setter directly to onValueChange. A callback expecting React.ChangeEvent<HTMLInputElement> is a different contract and is rejected in our checked consumer cases. Renaming that callback does not transform its parameter; an implementation must perform the conversion.

Exposing the original event can be reasonable when callers need event-specific behavior. Say why, type it explicitly, and avoid giving a prop a value-oriented name while passing an event. A reusable design-system field benefits from a stable semantic boundary, while a thin native-input wrapper may favor native props.

The callback type alone does not prove that the controlled parent updates its value. A parent could ignore the callback or apply an unintended transformation. Demonstrate the update path in the browser rather than describing a successful compile as proof of interactive correctness.

Ownership and validation are separate choices, with an error message required only for invalid feedback

Can an object spread bypass the intended restriction?

Test consumer values that existed before the JSX expression. An excess-property error on one fresh object literal is weaker evidence than a contract that also rejects a conflicting variable passed through a spread. The TypeScript object-types handbook explains the distinction between structural compatibility and excess-property checks.

For this API, the following consumer must fail:

const mixed = {
  id: "name",
  label: "Name",
  validation: { status: "idle" } as const,
  mode: "uncontrolled" as const,
  value: "Ada",
  defaultValue: "Lin",
};

// @ts-expect-error Uncontrolled mode forbids value.
<TextField {...mixed} />;

The optional never member makes the conflict part of compatibility with the uncontrolled branch. Simply leaving value out of that branch would describe less of the intended exclusion. Our compiler fixture checks this nonliteral spread separately from a direct JSX call.

This does not make TypeScript an exact-object validator. An unrelated extra key on a previously constructed value may remain structurally compatible. Be precise: the contract rejects the named conflicts under the tested configuration; it does not remove unknown properties from a runtime object.

Why does explicit undefined need its own test?

The official exactOptionalPropertyTypes option distinguishes an absent optional property from explicitly assigning undefined when that value is not declared. Enable it alongside strict checking for this exercise:

{
  "compilerOptions": {
    "strict": true,
    "exactOptionalPropertyTypes": true,
    "jsx": "react-jsx",
    "noEmit": true
  }
}

Our controlled case with defaultValue: undefined fails when exact optional checking is enabled. With that flag disabled, the same assignment is accepted and its expected-error directive becomes unused. The ordinary mixed string values still fail; the flag experiment concerns the explicit-undefined boundary.

Record the configuration with the result. Saying “this type always forbids the property” loses the condition that the experiment demonstrated. Likewise, do not infer a project's flags from a green editor window or from a different repository's defaults.

The local fixture used TypeScript 5.9.3, React 19.3.0, and @types/react 19.2.2. These are pinned reproduction versions, not a claim that every package is the latest. The React runtime and its type definitions are separate dependencies and both belong in your verification record.

Which negative cases should you demonstrate?

Compile real JSX consumers as well as plain object assignments. The original fixture accepts four valid consumers and independently rejects eight invalid cases. Removing their expected-error comments produced eight diagnostics, so the checks do not merely assume that the compiler complained somewhere.

Consumer caseExpected outcome
Controlled value with a string callbackAccept.
Uncontrolled default value without a callbackAccept.
Controlled value without its callbackReject.
Controlled value together with defaultValueReject.
Uncontrolled mode with value, directly or through a variable spreadReject both cases.
Invalid feedback missing its messageReject.
Valid feedback carrying a stale error messageReject.
Controlled defaultValue explicitly undefinedReject with exact optional checking.
Event-shaped callback supplied to the string callback propReject.

Use @ts-expect-error for a deliberately invalid example in a passing fixture, then confirm the directive becomes unused when the relevant protection is removed. Keep each case small enough that the intended diagnostic is identifiable. A broken import could otherwise make a negative test appear successful for the wrong reason.

Run an explicit type-check command. React's TypeScript documentation notes that its embedded sandboxes do not run the type checker. Seeing an example render there therefore does not establish that invalid props were rejected.

What must a browser test still establish?

Exercise the real component with a parent. In our local React fixture, the controlled field begins empty with “Name is required.” Typing Ada updates both the input and the parent's displayed value, removes the alert, and changes aria-invalid to false. Clearing it restores the required-message feedback.

The uncontrolled field begins with Lin. Typing Mei changes its DOM value and invokes the optional observation callback with Mei. Updating the parent's defaultValue prop to “New default” leaves the user's edited value as Mei. These are observations from the executed fixture, not simulated outputs inferred from the types.

Five browser checkpoints recorded that sequence and confirmed that both labels target existing inputs. The rendered invalid message is connected through aria-describedby. Those DOM checks do not substitute for testing an actual assistive-technology experience.

For an interview extension, ask what reset means: restore an initial value, accept a new server value, or discard the mounted control entirely. Specify that behavior before adding a reset prop. A successful initial-value test does not establish any of those additional requirements.

Where does this model stop protecting you?

The union describes valid props for one render. It cannot prove that a caller keeps the same ownership mode throughout a component's mounted lifetime. React documents that switching an input between controlled and uncontrolled usage is unsupported. A library must decide how to prevent, document, or detect that temporal misuse.

Nor can validation: Validation authenticate external JSON, establish a request's freshness, or guarantee that a message is nonempty. Keep those checks at the relevant construction or async boundary. The existing discriminated-union guide develops exhaustive state handling and stale-event policies separately.

In your explanation, name the guarantee you added and one guarantee still missing. “The compiler rejects a controlled field without its callback; the browser trace verifies that our sample parent updates” is a defensible result. Broader claims about every consumer need broader evidence.

Practise the component contract on a larger task

These PracHub records provide adjacent practice, not predictions of your exact interview. Translate each prompt's actual requirements into accepted and rejected consumers before borrowing this field's policy.

PracHub questionType-driven follow-up
Design a Reusable React Autocomplete Input: API, Portals, Debounce and CachingSeparate text ownership, selected item, and request feedback.
Implement and Improve React ComponentsDemonstrate a component boundary that rejects conflicting props.
Implement a multi-step form in ReactPreserve drafts while modeling validation and submission separately.
Implement a React flag loader with typewriter effectDistinguish valid props from lifecycle and timing guarantees.
Review and Improve Four AI-Assisted TypeScript Pull RequestsRequire a compiler counterexample before accepting a type-safety claim.

Start with the reusable autocomplete task. Choose one ownership rule, write a valid consumer and a conflicting spread consumer, and show the actual diagnostic. Finish by tracing one user edit through the parent and the rendered UI.

Sources and Further Reading


Comments (0)