Type a JavaScript library with TypeScript declaration files

8 steps · about 1 h 40 min · Intermediate

  1. Learn what declaration files are for (article, TypeScript, 5 min)

    Maps the handbook section you will work through.

  2. Write declarations by example (tutorial, TypeScript, 20 min)

    Turns API docs into declare statements, one pattern at a time.

  3. Identify the library's structure (article, TypeScript, 15 min)

    Global, module or UMD decides which template to use.

  4. Use the template for global libraries (reference, TypeScript, 10 min)

    A starting point for script-tag libraries.

  5. Understand how declarations merge (article, TypeScript, 15 min)

    Explains value, type and namespace meanings of one name.

  6. Generate .d.ts files from JSDoc-annotated JavaScript (tutorial, TypeScript, 10 min)

    Lets the compiler write declarations for you.

  7. Install and use types from @types (reference, TypeScript, 5 min)

    How projects pick up typings you or others publish.

  8. Contribute types to DefinitelyTyped (repo, GitHub, 20 min)

    The home of community typings and its contribution rules.