npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nick-vi/opencode-type-inject

v1.3.0

Published

OpenCode plugin that auto-injects TypeScript types into file reads and provides type lookup tools

Readme

opencode-type-inject

OpenCode plugin that auto-injects TypeScript types into file reads and provides type lookup tools.

Installation

Add to your opencode.json:

{
  "plugin": ["@nick-vi/opencode-type-inject"]
}

What It Does

Automatic Type Injection (Read Hook)

When an LLM reads a TypeScript or Svelte file, this plugin automatically:

  1. Extracts type signatures (functions, types, interfaces, enums, classes, constants)
  2. Resolves imported types from other files (up to 4 levels deep)
  3. Applies smart filtering (only types actually used in the code)
  4. Enforces a token budget with priority-based ordering
  5. Prepends the signatures to the file content

Custom Tools

The plugin also provides two tools:

  • lookup_type - Look up any type by name without reading files
  • list_types - List all types in the project

Example Output

When reading a file:

<types count="3" tokens="~85">
function getUser(id: string): User  // [offset=2,limit=8]

type User = { id: string; name: string; role: Role; }

type Role = { name: string; permissions: Permission[]; }  // [filePath=./lib/role.ts]

</types>

<file>
00001| import { User } from "./user";
00002| 
00003| export function getUser(id: string): User {
00004|   return { id, name: "test", role: { name: "admin", permissions: [] } };
00005| }
</file>

Key Features

Token Budget with Priority Ordering

Types are prioritized by importance:

| Tier | Contents | Priority | |------|----------|----------| | 1 | Function signatures | ALWAYS included | | 2 | Types used in function signatures | High | | 3 | Dependencies of tier 2 types | Medium | | 4 | Other local types | Low | | 5 | Imported types not yet included | Lowest |

Import Resolution

Types are automatically resolved from imported files up to 4 levels deep.

Smart Filtering

Only types actually used in the code are included. For partial file reads (with offset/limit), only types relevant to that section are injected.

Barrel File Detection

Files that only contain export * from statements are skipped.

Svelte Support

Svelte files (.svelte) are fully supported:

  • Extracts types from both <script lang="ts"> (instance) and <script module lang="ts"> (module) blocks
  • Resolves imports between Svelte and TypeScript files in any direction (TS → Svelte, Svelte → TS)
  • Calculates correct line numbers for each script block
  • Requires svelte as an optional peer dependency (only loaded if installed)

Understanding the Output

What Gets Shown

| What | Shown As | Why | |------|----------|-----| | Functions | Signature only | Implementation can be long; signature tells you how to call it | | Classes | Public members only | Private details are internal; public API is what matters | | Types/Interfaces | Full definition | They ARE the definition - nothing hidden | | Arrow functions | Only if explicitly typed | const fn: Type = ... is intentional API; const fn = () => {} is often implementation detail |

Location Comments

Since functions and classes only show signatures, we provide location hints so you can read the implementation when needed:

function processUser(id: string): User  // [offset=15,limit=28]

The format matches the read tool parameters directly - no translation needed.

When filePath is Included

// Direct import - you can see the import statement above
type User = { ... }

// Transitive import (2+ levels deep) - source not obvious
type Permission = { ... }  // [filePath=./lib/permission.ts]

Direct imports are visible in the file's import statements. Transitive imports aren't - so we include where they live for navigation and refactoring.

| Type | Local/Direct Import | Transitive Import (depth > 1) | |------|---------------------|-------------------------------| | function/class | // [offset=X,limit=Y] | // [filePath=...,offset=X,limit=Y] | | type/interface/enum | (none - full definition shown) | // [filePath=...] |

Tools

Both tools support TypeScript and Svelte files.

lookup_type

Look up type definitions by name (works with .ts, .tsx, and .svelte files).

Arguments:

  • name (required): Type name to search for
  • exact (optional): Exact match or contains. Default: true
  • kind (optional): Filter by kind (function, type, interface, enum, class, const)
  • includeUsages (optional): Include files that import this type. Default: false
  • limit (optional): Maximum results. Default: 5

Output includes:

## TypeName (kind)
File: ./path/to/file.ts [offset=9,limit=50]

## CounterProps (type)
File: ./components/Counter.svelte [offset=6,limit=5]

The offset and limit match the read tool parameters for easy navigation.

list_types

List all type names in the project (includes both TypeScript and Svelte files).

Arguments:

  • kind (optional): Filter by kind
  • limit (optional): Maximum results. Default: 100

License

MIT