DefinitelyTyped is a community repository of TypeScript declaration files for JavaScript libraries without built-in types. Its definitions are published as @types packages, giving TypeScript projects type safety, IntelliSense, and more reliable third-party integration. section 3.6
Use DefinitelyTyped when integrating untyped JavaScript dependencies:
- Install the library’s matching @types package as a development dependency when available. section 3.9
- Rely on TypeScript’s automatic lookup in node_modules/@types for compiler checking and IDE support. section 3.9
- Create a custom .d.ts file with declare module when no suitable community definition exists, then test it in TypeScript code. section 3.9
- Choose module declarations for imported libraries and global declarations for project-wide variables to keep type scope maintainable. section 3.9
Adding types to an untyped library
A TypeScript project identifies a JavaScript dependency without built-in declarations, installs its @types package if available, and otherwise adds a custom .d.ts file using declare module. The team tests the declarations so imports receive type checking and IntelliSense. section 3.9
Table 3.7 Key features of type safety and tools
|
Topic
|
Fundamentals
|
Applied skills
|
Advanced
|
|
Type narrowing
|
Use
typeof,
instanceof, and control flow analysis to narrow types.
|
Create user-defined type guards, handle discriminated unions.
|
Architect safe APIs with exhaustive type checks, leverage never for unreachable code.
|
|
Type assertions & casting
|
Use
as and angle-bracket syntax for casting.
|
Refactor code to reduce reliance on assertions and avoid unsafe casts.
|
Audit large codebases for unsafe assertions; enforce strict type safety policies.
|
|
Strictness & config
|
Enable
strict mode, explain key compiler config options.
|
Configure strictness for projects, resolve common strictness errors.
|
Architect enterprise-scale codebases with strictest settings, automate config validation across teams.
|
|
JavaScript interop & declaration files
|
Use
.d.ts files, import JS modules, explain
any.
|
Write custom declaration files, leverage
unknown and
never for safer interop.
|
Integrate with complex JS libraries; automate API type generation from OpenAPI/GraphQL schemas.
|
|
Tooling & build
|
Set up
tsc, configure a basic
tsconfig.json.
|
Integrate with bundlers (Webpack, Vite), enable source maps and incremental builds.
|
Architect monorepos, automate type checking in CI/CD pipelines, enforce code quality gates.
|
Compare declaration files, JavaScript interoperability, and related TypeScript type-safety practices. section 3.9

