JSPM

ts-declaration-location

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 334873
  • Score
    100M100P100Q183864F
  • License BSD-3-Clause

Determine where a ts type declaration comes from

Package Exports

  • ts-declaration-location

Readme

ts-declaration-location

npm version CI Coverage Status
code style: prettier GitHub Discussions BSD 3 Clause license Commitizen friendly semantic-release

Any donations would be much appreciated. 😄

Installation

# Install with npm
npm install -D ts-declaration-location

# Install with pnpm
pnpm add -D ts-declaration-location

# Install with yarn
yarn add -D ts-declaration-location

Usage Example

import typeMatchesSpecifier from "ts-declaration-location";
import type ts from "typescript";

function isTypeFromSomePackage(program: ts.Program, type: ts.Type) {
  const specifier = {
    from: "package",
    package: "some-package"
  };

  return typeMatchesSpecifier(program, specifier, type);
}

function isTypeFromSomeFile(program: ts.Program, type: ts.Type) {
  const specifier = {
    from: "file",
    path: "src/**/some.ts"
  };

  return typeMatchesSpecifier(program, specifier, type);
}

function isTypeFromTSLib(program: ts.Program, type: ts.Type) {
  const specifier = {
    from: "lib",
  };

  return typeMatchesSpecifier(program, specifier, type);
}