An open API service indexing awesome lists of open source software.

https://github.com/eythaann/readable-types

A utility library for do more easy works with generics in typescript.
https://github.com/eythaann/readable-types

development high-kinded-types high-order-types interfaces library opaque-type testing types typescript utilities validation

Last synced: 5 months ago
JSON representation

A utility library for do more easy works with generics in typescript.

Awesome Lists containing this project

README

        






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
```bash
npm install readable-types
```
### yarn
```bash
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:

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

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

type isNumber = IsNumber;
// ^? true
type isString = IsString
;
// ^? false

type B = Modify
// ^? { 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:
```tsx
describeType('MyType', () => {
testType('Should behave as expected', () => {
type MyType = /* Your type here... */;
type ExpectedType = /* Expected result here... */;
// More types...

assertType().equals(),
// More assertions...
});
});
```

### 2. Using Array
```tsx
describeType('MyType', () => {
testType('Should behave as expected', [
assertType().equals(),
assertType().not.equals(),
// More assertions...
]);
});
```

### 3. Using Object
```tsx
describeType('MyType', () => {
testType('Should behave as expected', {
test1: assertType().equals(),
test2: assertType().equals(),
'MyType should equal ExpectedType': assertType().equals(),
'really any text': assertType().equals(),
// 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:
```bash
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](https://github.com/Eythaann/readable-types/blob/master/LICENSE.txt)

## Authors
- [@eythaann](https://www.github.com/eythaann)

## 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](https://github.com/eythaann/readable-types/issues) on our GitHub repository. We appreciate your input and thank you for helping us make Readable Types even better!