Coder Social home page Coder Social logo

tsd-lite's Introduction

tsd-lite

Test your TypeScript types easily.

version license

This is a lighter version of tsd. Slightly reworked codebase allows tsd-lite to be a tool which simply tests your types.

Note: This library is intended for programmatic use only. For CLI implementation see jest-runner-tsd.

Motivation

While tsd suites perfectly for JavaScript libraries which declare their types in .d.ts files, its usage with monorepos written in TypeScript may become cumbersome. tsd-lite is an attempt to address these and similar issues.

Differences from tsd

  • tsd-lite performs only type testing without any additional checks or rules.
  • Includes only type related assertions: expectAssignable, expectDeprecated, expectType and their counterparts. The printType helper is removed.
  • Comes with no default compiler options.
  • Reads TypeScript compiler options from the nearest tsconfig.json for each test file (does not read options from package.json).
  • tsd-lite is optionally strict. You should add "strict": true to the nearest tsconfig.json (it can be project or test specific) to use strict assertions.
  • tsdErrors object is returned if tsd-lite encounters errors while parsing tsconfig.json or if syntax errors are found in the test files.
  • @tsd/typescript package is moved to peer dependencies.
  • tsd-lite allows only programmatic usage.

Install

yarn add -D tsd-lite @tsd/typescript

Remember to install @tsd/typescript. It is a required peer dependency.

Usage

import tsdLite from "tsd-lite";

const { assertionsCount, tsdResults, tsdErrors } = tsdLite(
  "/absolute/path/to/testFile.test.ts"
);

API Reference

tsdLite(testFilePath: string)

The exported function takes fully resolved path to a test file as an argument and returns an object:

{
  assertionsCount: number;
  tsdResults: Array<{
    messageText: string | ts.DiagnosticMessageChain;
    file?: ts.SourceFile;
    start?: number;
  }>;
};

tsd-lite will throw if TS compiler encountered an error while parsing tsconfig.json or found a syntax error while compiling the code.

License

MIT

tsd-lite's People

Contributors

mrazauskas avatar renovate-bot avatar renovate[bot] avatar lokshunhung avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.