Package Exports
- jstype-cli
- jstype-cli/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jstype-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
JSType CLI
| v1.2
JSType is a lightweight type checker for JavaScript, designed to help you catch type errors without switching to TypeScript. It scans your JavaScript files for inline JSDoc comment type annotations and verifies that variable values match their declared types.
Features
- π Non-intrusive type checking - Uses inline JSDoc comment syntax for declaring types.
- π‘ Type inference (--infer) β Optionally Infer types when JSDoc annotations are missing.
- π No build step required - Install and run the CLI tool (no need to change file extensions or refactor code).
- β Gradual adoption - Adopt type checking in stages. You can apply types to entire files or parts of files (great for legacy projects).
- β‘ Performance-Oriented - Skip files or file segments with special comments (/_: skip /, /: skip-remaining _/).
- π Full project report (--full) β Generate a JSON error log (jstype-errors.json) and summary for multi-file scans.
- π Rich type support - Handles primitive types, arrays, unions, and more.
- Primitive:
string,number,boolean,null,undefined - Complex:
object,array,function - Array types:
type[](e.g.string[]) - Union types:
type1|type2(e.g.string|number) - Function returns:
@returnsannotations drive returnβtype inference - Function parameters:
@paramannotations validate callβsite arguments
- Primitive:
Installation
Global Install
npm install -g jstype-cliLocal Development / Testing
git clone https://github.com/TruLie13/JSType
cd JSType
npm install
npm linkUsage
Basic Usage
#Works with path to file or entire folder
jstype <path> [options]Options
- [-i, --infer] - Enable type inference when JSDoc not present (reveals gaps in @type/@returns coverage).
- [-f, --full] - Full multiβfile report with JSON error log (jstype-errors.json) and summary.
Type Annotations
Variables
// Basic types
/** @type {string} */
let name = "Alice"; // β
No error
/** @type {number} */
let age = "twenty"; // β Type mismatch error
/** @type {boolean} */
let isValid = "true"; // β Type mismatch error (string, not boolean)
/** @type {array} */
let arr = [1, 2, 3]; // β
Matches array typeAssignments
/** @type {number} */
let count = 5; // β
Matches number type
/** @type {string} */
count = "10"; // β Cannot reassign type
count = "ten"; // β Type mismatch error in assignmentFunction Returns
/**
* @returns {array<string>}
*/
function getNames() {
return ["Alice", "Bob"];
}
let names = getNames(); // β
OKFunction Parameters
/**
* Concatenates two strings.
* @param {string} a
* @param {string} b
* @returns {string}
*/
function join(a, b) {
return a + b;
}
let good = join("foo", "bar"); // β
OK
let bad1 = join(1, "bar"); // β Param mismatch
let bad2 = join("foo", 2); // β Param mismatchResults Reported
JSType provides clear error messages when type mismatches are detected:
Output & Logs
- By default, JSType prints errors immediately and exits on the first file with errors.
- With --full: jstype-errors.json file is generated at project root and terminal displays summary (ex: 'Found 3 type error(s) in 2 files β scan time: 0.45s β see jstype-errors.json')
Error example
Success example
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Roadmap
- Add type check for function variables
- Add type check for component props
- Add type check for local imports
- Convert to package so it can be installed globally with npm
- Memory Management - garbage collecting