declare module "mathUtils" { export function add(a: number, b: number): number; } import { add } from "mathUtils"; console.log(add(3, 4));
The declaration file .d.ts only tells TypeScript about the shape of the module but does not provide any actual code. When running the compiled JavaScript, since there is no implementation for add, it results in a runtime TypeError.
PI with type number in a declaration file.In declaration files, you use declare to tell TypeScript about the existence and type of variables without assigning values. Option A correctly declares PI as a constant of type number without initialization.
interface User {
name: string;
age: number;
greet(): void
}In TypeScript interfaces, each property declaration must end with a semicolon or comma. The line name: string is missing a semicolon, causing a syntax error.
format that can be called with either one string argument or two string arguments. Which declaration is correct in a .d.ts file?Function overloads in declaration files are declared as multiple declare function statements with the same name but different parameters. Option B correctly declares two overloads for format.
data in the TypeScript code?declare module "dataModule" { interface Data { id: number; value: string; } const data: Data[]; export default data; } import data from "dataModule"; // What is the type of 'data' here?
The declaration states const data: Data[]; which means data is an array of Data objects. Each Data object has id as a number and value as a string.