Giter Club home page Giter Club logo

readable-types's Introduction


Readable-Types

With Readable-Types, you can create TypeScript types that are easy to read and understand. The library provides a set of intuitive and expressive utilities for defining complex types, reducing the need for manual type checking and making your code more reliable.

Whether you're building a small project or a large enterprise application, Readable Types can help you save time and reduce errors by providing a more readable and maintainable way to define your types.

In addition to making type creation more manageable, Readable Types also includes a suite of testing utilities to help ensure that your types are correct and reliable. With support for both unit and integration testing, you can rest assured that your types are functioning as expected.

Get started with Readable Types today and take the first step toward a more readable, reliable, and maintainable codebase!




Installation

To add the library to your project just need to run:

npm

npm install readable-types

yarn

yarn add readable-types



Usage

Our library provides a comprehensive set of TypeScript utility functions that are ready to use out of the box. Simply import the library into your project or file, and its all!.

Here's a quick example of how you might use Readable-Types in your project:

import { IsString, IsNumber, Modify } from 'readable-types';

type A = { a: string, b: number }

type isNumber = IsNumber<A['b']>;
//   ^? true
type isString = IsString<A['b']>;
//   ^? false

type B = Modify<A, { a: number, c: object }>
//   ^? { a: number, b: number, c: object }



Testing with Readable-Types

In order to verify that your types are functioning as expected, it's essential to implement testing. Readable-Types provides a suite of utilities to aid in this process. You can write your tests in several different ways based on your preferences and requirements.

Here's how to do it:

1. Basic Syntax

The simplest way to create tests is by using the testType function inside a describeType block:

describeType('MyType', () => {
  testType('Should behave as expected', () => {
    type MyType = /* Your type here... */;
    type ExpectedType = /* Expected result here... */;
    // More types...

    assertType<MyType>().equals<ExpectedType>(),
    // More assertions...
  });
});

2. Using Array

describeType('MyType', () => {
  testType('Should behave as expected', [
    assertType<MyType>().equals<ExpectedType>(),
    assertType<MyType>().not.equals<UnexpectedType>(),
    // More assertions...
  ]);
});

3. Using Object

describeType('MyType', () => {
  testType('Should behave as expected', {
    test1: assertType<MyType>().equals<ExpectedType>(),
    test2: assertType<MyType>().equals<ExpectedType>(),
    'MyType should equal ExpectedType': assertType<MyType>().equals<ExpectedType>(),
    'really any text': assertType<MyType>().equals<ExpectedType>(),
    // More labeled assertions...
  });
});

Execute Test

To test with our library, we use the TypeScript compiler reading the AST. For "run" the test you need to ejecute:

rtft

Additionally, we recommend adding this command to your Husky pre-commit hook to ensure that any changes to these files are caught before they are committed to the repository.

These are the basic ways to create type tests with Readable-Types. Remember, testing your types is crucial to maintain robust and bug-free TypeScript code. Happy testing!




Compatibility

Readable-Types is compatible with TypeScript versions 4.2 and above.

Roadmap

We're always working to improve and expand Readable-Types. Here's a sneak peek at what's coming up in future versions:

  • More type utilities for common use cases
  • Enhanced testing capabilities

License

MIT

Authors

Feedback

We're always looking to improve our library, and your feedback is essential to that process. If you have any suggestions, comments, or bug reports, please feel free to open an issue on our GitHub repository. We appreciate your input and thank you for helping us make Readable Types even better!

readable-types's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

rexsaltu

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.