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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@itrocks/parameter-name

v0.0.4

Published

Runtime parameter name reflection from TypeScript declaration files

Downloads

472

Readme

npm version npm downloads GitHub issues discord

parameter-name

Runtime parameter name reflection from TypeScript declaration files.

This documentation was written by an artificial intelligence and may contain errors or approximations. It has not yet been fully reviewed by a human. If anything seems unclear or incomplete, please feel free to contact the author of this package.

Installation

npm i @itrocks/parameter-name

Usage

@itrocks/parameter-name provides a single function parameterNamesFromFile(fileName, className, methodName) that reads the corresponding TypeScript declaration file (.d.ts) and returns the list of parameter names for a given class constructor or method.

It is typically used by other @itrocks/* packages to implement decorators that need to know the names of constructor parameters at runtime (for example to bind data, build forms, or perform dependency injection), but you can also call it directly in your own code.

Important: the function expects a .d.ts file to exist next to the runtime file, with the same base name. For example, if fileName is /dist/user.js, then a matching /dist/user.d.ts file must be present.

Minimal example

import { parameterNamesFromFile } from '@itrocks/parameter-name'

const parameterNames = parameterNamesFromFile(
  '/absolute/path/to/dist/user.js',
  'User',
  'constructor'
)

// e.g. ['id', 'email', 'displayName']
console.log(parameterNames)

With the following declaration in the TypeScript .d.ts file:

declare class User {
  constructor(id: number, email: string, displayName?: string)
}

the call above will return ['id', 'email', 'displayName'].

Complete example with runtime resolution

In a more realistic scenario, you compute the file name from the location of the running module and use the parameter names inside your own reflection or binding logic.

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { parameterNamesFromFile } from '@itrocks/parameter-name'

// Example class defined in this module
export class User {
  constructor(id: number, email: string, isAdmin = false) {}
}

function parameterNamesOfUserConstructor(): string[] {
  // Compute the compiled file path (e.g. dist/user.js)
  const fileName = fileURLToPath(import.meta.url)

  return parameterNamesFromFile(
    fileName,
    'User',
    'constructor'
  )
}

const names = parameterNamesOfUserConstructor()
// ['id', 'email', 'isAdmin']
console.log('User constructor parameters:', names)

You can then reuse names to automatically map user input, define validation rules, or build a debug/logging helper that displays argument names alongside their values.

API

function parameterNamesFromFile(fileName: string, className: string, methodName: string): string[]

Reads the TypeScript declaration file (.d.ts) corresponding to the given fileName and extracts the parameter names of a specific class constructor or method.

Parameters

  • fileName – path to the compiled JavaScript file whose declaration file you want to inspect. The function automatically replaces the extension with .d.ts and reads that file. A matching declaration file must exist.
  • className – the exact name of the class as it appears in the declaration file.
  • methodName – name of the method whose parameters you want to read. Use 'constructor' to retrieve constructor parameter names.

Return value

  • string[] – ordered list of parameter names. If a parameter does not have a simple identifier name (for example a destructured parameter), its entry in the array will be an empty string.

Notes and limitations

  • Only class declarations are supported; free functions are not inspected.
  • The package relies on .d.ts files generated by the TypeScript compiler. If those files are missing or out of sync with the runtime code, the result may be incomplete or empty.

Typical use cases

  • Implement decorators that infer constructor parameter names at runtime to bind values or perform dependency injection.
  • Generate forms or validation schemas by matching parameter names with metadata or user input fields.
  • Build debugging helpers that log both parameter names and values when methods or constructors are called.
  • Create small reflection utilities in other @itrocks/* packages or in your own framework code, without having to manually parse TypeScript declaration files yourself.