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

chai_typescript_type_annotation_tests

v1.4.2

Published

This provides some chai tests for verifying type annotation in Typescript

Readme

Chai Typescript Type Annotation Tests

Intro

This package provides helpers for testing TypeScript type annotations in Chai/Mocha test cases. It is designed to help instructors and teams enforce explicit typing in student or team code.

Installation

  • Run npm install chai_typescript_type_annotation_tests to install the package.
  • Once installed, import and use any of the functions in your Chai/Mocha test cases.

Usage


Variable Type Annotation

expectVariableExplicitTypeAnnotation(testFilePath: string, varName: string, typeName: string)

Asserts that a variable is declared with an explicit type annotation matching the expected type.

Example:

expectVariableExplicitTypeAnnotation(myFilePath, "userWithName", "User");

Function Return Type Annotation

expectFunctionReturnTypeAnnotation(testFilePath: string, functionName: string, returnType: string)

Checks that a function (declaration or arrow function assigned to a variable) has an explicit return type annotation matching the expected type.

Example:

expectFunctionReturnTypeAnnotation(myFilePath, "getUser", "User");

Function Parameter Type Annotation (by parameter name)

expectFunctionParameterTypeAnnotation(testFilePath: string, functionName: string, paramName: string, paramType: string)

Asserts that a specific parameter of a function (by name) has an explicit type annotation matching the expected type.

Example:

expectFunctionParameterTypeAnnotation(
  myFilePath,
  "updateUser",
  "userId",
  "string"
);

Function Parameter Type Annotation (by parameter order)

matchFunctionParameterTypeAnnotation(testFilePath: string, functionName: string, expectedParameterTypeArray: string[])

Checks that the parameters of a function have explicit type annotations matching the expected types in order.

Example:

matchFunctionParameterTypeAnnotation(myFilePath, "createUser", [
  "string",
  "number",
  "boolean",
]);

Class Property Type Annotation

expectClassPropertyTypeAnnotation(testFilePath: string, className: string, propertyName: string, typeName: string)

Asserts that a class property is declared with an explicit type annotation matching the expected type.

Example:

expectClassPropertyTypeAnnotation(myFilePath, "Person", "name", "string");

Class Method Return Type Annotation

expectClassMethodReturnTypeAnnotation(testFilePath: string, className: string, methodName: string, returnType: string)

Checks that a class method has an explicit return type annotation matching the expected type.

Example:

expectClassMethodReturnTypeAnnotation(
  myFilePath,
  "User",
  "getFullName",
  "string"
);

Class Method Parameter Type Annotation

matchClassMethodParameterTypeAnnotation(testFilePath: string, className: string, methodName: string, expectedParameterTypeArray: string[])

Checks that the parameters of a class method have explicit type annotations matching the expected types in order.

Example:

matchClassMethodParameterTypeAnnotation(myFilePath, "User", "setName", [
  "string",
  "string",
]);

How These Helpers Work

Each helper parses your TypeScript file using the TypeScript compiler API, traverses the Abstract Syntax Tree (AST), and inspects nodes to verify that type annotations are present and correct. This allows you to write tests that enforce explicit type annotations in student or team code.


Contributing

Pull requests and suggestions are welcome! If you find a bug or want to request a new feature, please open an issue.


License

MIT