diff --git a/types/seamless-immutable/index.d.ts b/types/seamless-immutable/index.d.ts index d3d2ef5b6a..b781523ef2 100644 --- a/types/seamless-immutable/index.d.ts +++ b/types/seamless-immutable/index.d.ts @@ -18,6 +18,10 @@ declare namespace SeamlessImmutable { merger?(a: any, b: any, config: any): any; } + interface ReplaceConfig { + deep: boolean; + } + interface Options { prototype?: any; } @@ -75,6 +79,8 @@ declare namespace SeamlessImmutable { without(property: K): ImmutableObject; without(...properties: K[]): ImmutableObject; without(filter: (value: T[K], key: K) => boolean): ImmutableObject; + + replace(valueObj: S, options?: ReplaceConfig): ImmutableObject; } interface ImmutableArrayMixin { @@ -92,6 +98,8 @@ declare namespace SeamlessImmutable { function isImmutable(target: any): boolean; function ImmutableError(message: string): Error; + + function replace(obj: ImmutableObject, valueObj: S, options?: ReplaceConfig): ImmutableObject; } declare function SeamlessImmutable(obj: T[], options?: SeamlessImmutable.Options): SeamlessImmutable.ImmutableArray; diff --git a/types/seamless-immutable/seamless-immutable-tests.ts b/types/seamless-immutable/seamless-immutable-tests.ts index ddec87e81d..cccb2d7f96 100644 --- a/types/seamless-immutable/seamless-immutable-tests.ts +++ b/types/seamless-immutable/seamless-immutable-tests.ts @@ -44,6 +44,12 @@ interface ExtendedUser extends User { { const isImmutable: boolean = Immutable.isImmutable(Immutable.from([0, 2])); + const user1: Immutable.ImmutableObject = Immutable.from({ + firstName: 'Angry', + lastName: 'Monkey' + }); + const replacedUser01 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' }); + const replacedUser02 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' }, { deep: true }); } // @@ -124,4 +130,8 @@ interface ExtendedUser extends User { const firstNameWithDynamicPathWithDefault = immutableUser.getIn(['first' + 'name'], ''); const line1WithoutDefault = immutableUserEx.getIn(['address', 'line1']); const line1WithDefault = immutableUserEx.getIn(['address', 'line1'], ''); + + // replace + const replacedUser01 = immutableUser.replace({ firstName: 'Super', lastName: 'Monkey' }); + const replacedUser02 = immutableUser.replace({ firstName: 'Super', lastName: 'Monkey' }, { deep: true }); }