dataclass
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

The library brings flexibility and usefulness of data classes from Kotlin, Scala, or Python to TypeScript and JavaScript.

Read full docs on the homepage.

import { Data } from "dataclass";

// 1. easily describe your data classes using just language features
class User extends Data {
  name: string = "Anon";
  age: number = 0;
}

// 2. instantiate classes while type systems ensure correctness
let user = User.create({ name: "Liza", age: 23 });
// > User { name: "Liza", age: 23 }

// 3. make changes while benefiting from immutable values
let updated = user.copy({ name: "Ann" });
// > User { name: "Ann", age: 23 }
updated = updated.copy({ name: "Liza" });
// > User { name: "Liza", age: 23 }

// 4. compare objects by their value, not reference
console.log(user === updated, user.equals(updated));
// > false, true

/dataclass/

    Package Sidebar

    Install

    npm i dataclass

    Weekly Downloads

    4,660

    Version

    2.1.1

    License

    ISC

    Unpacked Size

    4.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • alexeyraspopov