Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ts-declaration-location

RebeccaStevens954.7kBSD-3-Clause1.0.5

Determine where a ts type declaration comes from

readme

ts-declaration-location

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

Any donations would be much appreciated. 😄

Enterprise Users

ts-declaration-location is available as part of the Tidelift Subscription.

Tidelift is working with the maintainers of ts-declaration-location and a growing network of open source maintainers to ensure your open source software supply chain meets enterprise standards now and into the future. Learn more.

Installation

npm

# Install with npm
npm install ts-declaration-location

# Install with pnpm
pnpm add ts-declaration-location

# Install with yarn
yarn add ts-declaration-location

# Install with bun
`bun add ts-declaration-location

jsr

# Install in a node project
npx jsr add @rebeccastevens/ts-declaration-location

# Install in a deno project
deno add jsr:@rebeccastevens/ts-declaration-location

# Install in a bun project
bunx jsr add @rebeccastevens/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);
}

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

1.0.5 (2024-11-28)

Bug Fixes

1.0.4 (2024-08-01)

1.0.3 (2024-07-19)

Bug Fixes

  • handling of global module declarations (45e884c)

1.0.2 (2024-07-06)

Bug Fixes

  • types declared in module declaration are now handle (316969b)

1.0.1 (2024-05-06)

Bug Fixes

  • how testing if a type is a from a local file is done (3312d1c)

1.0.0 (2024-04-14)

Features