Consider this TypeScript code that imports a library without an installed @types package. What will the TypeScript compiler report?
import _ from 'lodash'; const result = _.chunk([1, 2, 3, 4], 2); console.log(result);
Think about what happens if TypeScript has no type info but the package is installed.
If the @types/lodash package is missing but lodash is installed, TypeScript treats the import as having type any. This means no compile error, but you lose type safety.
What is the main purpose of the DefinitelyTyped repository in the TypeScript ecosystem?
Think about what type definitions are and who maintains them when libraries don't provide their own.
DefinitelyTyped is a community repository that hosts type definition files (.d.ts) for JavaScript libraries that do not include their own TypeScript types.
Given this TypeScript code snippet, what error will the compiler show if @types/express is not installed?
import express from 'express'; const app = express(); app.get('/', (req, res) => { res.send('Hello World'); });
Consider what happens when the type declarations for a module are missing.
If @types/express is missing, TypeScript cannot find type declarations for the 'express' module and throws an error about missing module or types.
Assuming @types/moment is installed, which import statement correctly imports the moment library with types?
Check the recommended import style for ES modules with default export.
The @types/moment package defines the module as a namespace export, so import * as moment from 'moment'; is the correct syntax.
You want to use a JavaScript library foo-lib in your TypeScript project, but there is no @types/foo-lib package available. What is the best way to add type safety?
Think about a practical way to get some type safety quickly.
Creating a local declaration file with minimal types lets you get type safety without waiting for community types. Using just declare module without details loses safety. Forking DefinitelyTyped is good but takes time.