yoklainterview sim

Frontend Typescript Modules Declarations Interview Questions

75 verified Frontend Typescript Modules Declarations interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Typescript Modules DeclarationsDifficulty 1
What is the purpose of a .d.ts file in a TypeScript project?
  • aIt contains executable JavaScript that runs at build time
  • bIt describes a module's API shape/types, with no implementation code
  • cIt is a config file that replaces tsconfig.json
  • dIt stores the compiled output of a .ts file
Explanation:A declaration file (.d.ts) contains only type information — interfaces, function signatures, variable declarations — with no runtime code. It tells the compiler what the shape of a module or library is, so TypeScript can type-check code that uses it even if the implementation was written in plain JavaScript or is compiled separately.
Typescript Modules DeclarationsDifficulty 1
What does the declare keyword tell the TypeScript compiler?
  • aThat the following variable should be exported automatically
  • bThat the code block should be removed during compilation
  • cSomething exists at runtime, without TypeScript generating code for it
  • dThat the variable's type must be inferred as any
Explanation:declare is an ambient declaration: it tells the compiler 'trust me, this exists somewhere at runtime' (e.g. a global provided by a script tag, or a variable injected by a bundler) without TypeScript emitting any JavaScript for that declaration. It's purely a type-checking-time construct.
Typescript Modules DeclarationsDifficulty 1
import type { User } from './types';
import { fetchUser } from './api';

What is the main purpose of writing import type instead of a plain import here?
  • aIt marks User as type-only, safely erasable from the compiled output
  • bIt makes User available at runtime as a global variable
  • cIt forces User to be re-exported from the current file automatically
  • dIt is required syntax whenever importing an interface, with no other effect
Explanation:import type explicitly marks an import as type-only. Since types don't exist at runtime, the compiler can safely erase this import entirely from the emitted JavaScript, rather than having to analyze whether User is also used as a value. It has no effect on how User behaves as a type — only on what gets emitted.
Typescript Modules DeclarationsDifficulty 2
You install an npm package that is written in plain JavaScript with no type definitions. What is the typical TypeScript solution?
  • aTypeScript refuses to compile the project until the package is rewritten in TypeScript
  • bThe package is automatically treated as never and cannot be imported at all
  • cYou must convert the entire package's source code to .ts files yourself
  • dProvide (or install from @types/...) a .d.ts file for the package
Explanation:For plain-JS packages without built-in types, the common approach is to add type declarations separately — either the community-maintained @types/<package> package (DefinitelyTyped) or a hand-written .d.ts file — so TypeScript knows the shape of the API without needing the package's own source to be TypeScript.
Typescript Modules DeclarationsDifficulty 2
// global.d.ts
declare const __APP_VERSION__: string;

// app.ts
console.log(__APP_VERSION__.toUpperCase());

__APP_VERSION__ is actually injected by the bundler at build time and never assigned anywhere in the TypeScript source. What happens when app.ts is compiled?
  • aA compile error: __APP_VERSION__ is used before being assigned a value
  • bA runtime error, since TypeScript inserts a check that throws if the variable is undefined
  • cIt compiles — declare says the variable exists elsewhere, no assignment needed
  • dTypeScript automatically replaces __APP_VERSION__ with the string 'unknown' during compilation
Explanation:declare const is an ambient declaration — it asserts that __APP_VERSION__ exists as a string somewhere at runtime (here, injected by the bundler), without TypeScript requiring or generating any assignment for it. The compiler simply trusts the declaration and type-checks .toUpperCase() against string. TypeScript does not verify or provide the actual runtime value.
Typescript Modules DeclarationsDifficulty 2
What is the key difference between export and export type for an interface?
  • aexport type guarantees erasure, but interfaces already have no runtime form
  • bexport type makes the interface usable both as a type and as a runtime value
  • cexport alone is invalid syntax for interfaces; export type is required
  • dexport type changes the interface into a type alias automatically
Explanation:Interfaces are already pure type-level constructs with no runtime representation, so export and export type behave the same in practice for an interface — both get erased. export type becomes meaningfully different mainly for re-exports of names that could otherwise be ambiguous between type and value (e.g. re-exporting a class used only as a type).

Test yourself against the 2925-question Frontend bank.

Start interview