New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ts-features

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-features

some typescript features like rust

latest
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

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);

Keywords

pattern-matching

FAQs

Package last updated on 26 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts