Skip to content

Latest commit

 

History

History
59 lines (51 loc) · 4.5 KB

File metadata and controls

59 lines (51 loc) · 4.5 KB

The Problems

You want to use a 3rd-party Package, but it doesn't have the Declarations You Need

  • it has type declarations, but not all of the ones you want
  • it has type declarations, but you encounter an error that prevents you from writing your code
  • it has type declarations, but they're incompatible with your module type
  • it doesn't have type declarations at all

Writing Good Declaration Files is Difficult

  • Javascript is complex, so TypeScript must be complex, too
  • There are multiple ways to express the same types
  • Javascript package documentation is often unclear regarding types
  • Scoping of declaration elements can be tricky
  • Making declaration files compatible with different module systems is tricky
  • It's hard to know what elements to type and what not to type
  • Writing a declaration file leads to learning more about the package than you want to know

Guidelines

  • Follow the recommendations at DefinitelyTyped
  • Study existing declarations for similarly shaped packages at DefinitelyTyped
  • Use the names from the documentation whenever possible
  • Carefully select type names that communicate their usage
  • Use namespaces to keep your declarations out of the global scope
  • Respect the methods for using a package: ambient and/or external
  • Don't try to get package owners to incorporate TypeScript declarations
  • packages change over time, including being renamed
  • if you fix an existing type declaration, contribute your change back to the community
    ...or pay a heavy "merge tax" during your subsequent updates

Resources

Examples

package or spec declaration notes
tv4 tv4 typings
imap imap typings SO help
nodemailer-pickup-transport nodemailer-pickup-transport typings
mailparser mailparser typings This package disappeared from DT at one point
pino pino typings PR to DefinitelyTyped, feedback from package author
seneca seneca typings help from package authors
GeoJSON GeoJSON typings emailed author
component-emitter component-emitter typings
node node.js typings

How to Submit your Type Declarations

  • I recommend using DefinitelyTyped PRs for now
    tsd and typings both use DefinitelyTyped
    The other systems are too new, and I prefer to wait for other people to fix the bleeding edge problems.
  • put your submissions on a branch named after the package name