Using JavaScript libraries

suggest change

Many packages ship their own TypeScript declarations. Try importing the package first. If declarations are not bundled, look for a matching community package under @types:

npm install package-name
npm install --save-dev @types/package-name

Use the import style documented by the package and choose compiler settings that match the runtime. Prefer ECMAScript module syntax in new code. The older import = require(...) form remains useful for some CommonJS packages that use export = declarations.

import { parse } from "some-package";

const result = parse("input");

Do not silence a whole library with a shorthand ambient module declaration (declare module "package-name"), which types the module as any, when a small local declaration can describe the API you actually use. Declarations describe runtime code; they do not provide an implementation.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents