Determine where a ts type declaration comes from
npm install ts-declaration-location


\





Any donations would be much appreciated. 😄
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.
``shInstall with npm
npm install ts-declaration-location
$3
`sh
Install in a node project
npx jsr add @rebeccastevens/ts-declaration-locationInstall in a deno project
deno add jsr:@rebeccastevens/ts-declaration-locationInstall in a bun project
bunx jsr add @rebeccastevens/ts-declaration-location
`Usage Example
`ts
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);
}
``