Immutable Record Typings
Typings for Immutable Record which provides better type safety out of the box.
Installation
This plugin requires minimum immutable 3.8.1, typescript 2.3.0
npm install --save-dev immutable-record-typings
There are two ways to enable typings augmentation:
Recommended way is adding "./node_modules/immutable-record-typings/*"
to include
section in your tsconfig.json
, here is an example:
You can also import 'immutable-record-typings'
in entry file of your application instead of adding it to tsconfig.json
.
We don't provide it as a @types
package because it would be not compatible with current typings.
So the safer way is to provide it as a separate npm package.
Also, Immutable v4 is on the way with similar typings :)
Features
This package adds generic type to the Record
definition. Thanks to this, we can make records type safe
(excluding mergeIn
, mergeDeepIn
, setIn
, deleteIn
, removeIn
and updateIn
methods - typescript limitations).
Let's say that we have Post.ts
file:
;;; // we use PascalCase because of names conflicts issue in records - // for example, a groupBy field will not work, because Record already has the groupBy method ;
Or if we are minimalist. we can make it even shorter - typescript will guess PostRecord
type:
;;; ;
To create new record object, we can use functional or object-oriented approach:
; ;;
To extend record class, we can use extends
keyword:
;;
License
MIT