1.3.5 • Published 1 year ago

ts-features v1.3.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

TS-Features

This library is for using typescript more comfortable, and bring rust features to typescript!

Usage

installation

Type at your shell

yarn add ts-features

and register transformer to tsconfig.json

{
    "compilerOptions": {
        "plugins": [
            { "transform": "ts-features/lib/transformer" }
        ]
    }    
}

Also, you should use

yarn ttsc

instead of

yarn tsc

pattern-matching

Write interface like this

interface Color {
    red: [string];
    green: [string];
    blue: [string];
}

And, make interface as constant constructor object

const Color = to_enum<Color>();

And, import match function

import { match } from "ts-features";

Finally, you can use pattern matching!

const result = match<string, Color>(Color.Red(["rose"]), {
    Red: ([first]) => `${first} red`,
    Blue: ([first]) => `${first} blue`,
    Green: ([first]) => `${first} green`,
});

expect(result).toBe("rose red");

You can discover samples at tests!

Rust-like error process

You can import these classes

import { Result, Err, Ok } from "ts-features";

And, just use it as if you writing rust code!

const result: Result<{ a: number }, string> = Ok({ a: 1 });
expect(result.isOk).toBe(true);

const result_err: Result<{ a: number }, string> = Err("error");
expect(result_err.isOk).toBe(false);
1.3.5

1 year ago

1.3.4

1 year ago

1.2.0

2 years ago

1.1.0

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago