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

eslint-plugin-type-inference

v0.1.0

Published

Type-aware ESLint rules for safely preferring TypeScript inference.

Readme

eslint-plugin-type-inference

Type-aware ESLint rules that prefer TypeScript inference only when a counterfactual compiler check shows the change is safe.

Status

The initial rule is intentionally conservative and opt-in. It supports typescript-eslint's JavaScript compiler-API range through TypeScript 6.0. TypeScript 7 does not yet expose the stable API this rule needs.

Installation

npm install --save-dev eslint-plugin-type-inference typescript-eslint typescript

Flat configuration

Typed linting must be enabled. projectService is the recommended typescript-eslint configuration:

import typeInference from 'eslint-plugin-type-inference';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  ...tseslint.configs.recommendedTypeChecked,
  {
    languageOptions: {
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
    plugins: {
      'type-inference': typeInference,
    },
    rules: {
      'type-inference/no-inferrable-return-type': 'error',
    },
  },
);

Rules

No rule is enabled by a recommended preset in v1.

What the rule reports

The rule reports local function declarations, function expressions, and arrow functions when removing the annotation preserves both TypeScript's complete callable signature and its diagnostics. These examples are reported and automatically fixed:

// Primitive return type
function add(a: number, b: number): number {
  return a + b;
}

// Arrow function and object return type
const makePoint = (x: number, y: number): { x: number; y: number } => ({ x, y });

// Generic inferred from a parameter
function identity<T>(value: T): T {
  return value;
}

// Async function
async function count(): Promise<number> {
  return 1;
}

// Contextually typed callback
const increment: (value: number) => number = (value): number => value + 1;

export {};

The resulting code is:

function add(a: number, b: number) {
  return a + b;
}

const makePoint = (x: number, y: number) => ({ x, y });

function identity<T>(value: T) {
  return value;
}

async function count() {
  return 1;
}

const increment: (value: number) => number = (value) => value + 1;

export {};

Exact void, unknown, never, and Promise<void> annotations can also be reported. They are not special-cased as safe: each one must pass the same compiler comparison.

What the rule does not report

Public API annotations are retained in v1, including functions exported where they are declared or exported later:

export function add(a: number, b: number): number {
  return a + b;
}

function subtract(a: number, b: number): number {
  return a - b;
}
export { subtract };

Annotations that affect inference or checking are also retained:

// Without the annotation, TypeScript widens the return type to string.
function status(): 'ok' {
  return 'ok';
}

// Without the annotation, TypeScript infers number[] rather than a tuple.
function pair(): [number, number] {
  return [1, 2];
}

// The annotation intentionally hides the concrete implementation type.
function hidden(): unknown {
  return 1;
}

// The annotation produces an excess-property diagnostic inside the body.
function invalidPoint(): { x: number } {
  return { x: 1, y: 2 };
}

export {};

The conservative v1 exclusions are not reported even when an individual case might appear inferable:

// Recursive function
function factorial(n: number): number {
  return n < 2 ? 1 : n * factorial(n - 1);
}

// Return-only generic
function make<T>(): T {
  throw new Error();
}

// Type predicate
function isString(value: unknown): value is string {
  return typeof value === 'string';
}

// Method
class Calculator {
  add(a: number, b: number): number {
    return a + b;
  }
}

// `any` in the return type
async function unsafe(): Promise<any> {
  return JSON.parse('null');
}

export {};

The rule also retains an annotation when removing it would leave a type import or local type declaration unused:

interface User {
  id: string;
}

const makeUser = (): User => ({ id: '1' });
void makeUser;

export {};