type-safe-immutable-record
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Type-safe Immutable Record

wercker status

A strongly typed immutable-js record interface.

This interface was strongly inspired by typed-immutable-record, but restricts the interface, allowing only methods that can play nicely with TypeScript's interface system. So far the only method on the interface is merge. If you want to add more methods, open an issue and start a discussion so that we can make sure to keep this interface as safe as possible.

Usage

This package contains only two things. An interface which should be extended from a specific way describe below, and a wrapper around Immutable.Record that usses the interface.

import Record, { RecordBase } from 'type-safe-immutable-record'
 
export interface PersonFields {
  name: string
  age: number
}
 
export interface PersonChange {
  name?: string
  age?: number
}
 
export interface Person extends RecordBase<PersonChange, Person>, PersonFields {}
 
export const Person = Record<PersonFields, PersonChange, Person>({
  name: '',
  age: 0,
})
 
const person = Person({
  name: 'Dale Gribble',
  age: 47
})
 
person.age === 47
 
const alias = person.merge({name: 'Rusty Shackleford'})
 
alias.name === 'Rusty Shackleford'

Package Sidebar

Install

npm i type-safe-immutable-record

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • ooesili