Skip to content

Instantly share code, notes, and snippets.

@jbouhier
Last active February 14, 2023 22:34
Show Gist options
  • Save jbouhier/f18e1c5b5531ff29490cf050e91ed010 to your computer and use it in GitHub Desktop.
Save jbouhier/f18e1c5b5531ff29490cf050e91ed010 to your computer and use it in GitHub Desktop.
TypeScript extend type declaration of a module/package

TypeScript: Extend package types

// When a package doesn't have any types, we can silence TS with
import * as someLibrary from "some-library"

// And extend some types if we want better type safety
declare module "some-library" {
  export function missingFunctionDeclaration(): {
    x: number
    y: number
    someOtherValue: string
  }
}

// To extend a package's types, look at the package's
// source code and declare types accordingly

// That's it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment