From bd54249da7ce63587d342ca046ea819a58349bc1 Mon Sep 17 00:00:00 2001 From: Stepan Burguchev Date: Mon, 10 Jul 2017 09:25:33 +0300 Subject: [PATCH] set/update fallbacks, tests, tslint coverage --- types/seamless-immutable/index.d.ts | 2 ++ .../seamless-immutable-tests.ts | 23 +++++++++++-------- types/seamless-immutable/tslint.json | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 types/seamless-immutable/tslint.json diff --git a/types/seamless-immutable/index.d.ts b/types/seamless-immutable/index.d.ts index c027c83429..d40c609dd4 100644 --- a/types/seamless-immutable/index.d.ts +++ b/types/seamless-immutable/index.d.ts @@ -36,6 +36,7 @@ declare namespace SeamlessImmutable { interface IImmutableObject { set(property: K, value: T[K]): ImmutableObject; + set(property: string, value: TValue): ImmutableObject; setIn (propertyPath: [ K ], value: T[K]): ImmutableObject; setIn @@ -54,6 +55,7 @@ declare namespace SeamlessImmutable { merge(part: DeepPartial, config?: MergeConfig): ImmutableObject; update(property: K, updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; + update(property: string, updaterFunction: (value: TValue, ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; updateIn (propertyPath: [ K ], updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; updateIn diff --git a/types/seamless-immutable/seamless-immutable-tests.ts b/types/seamless-immutable/seamless-immutable-tests.ts index 8374056fcc..64cbfdd6cb 100644 --- a/types/seamless-immutable/seamless-immutable-tests.ts +++ b/types/seamless-immutable/seamless-immutable-tests.ts @@ -5,7 +5,7 @@ import * as Immutable from 'seamless-immutable'; interface User { firstName: string; lastName: string; -}; +} interface Address { line1: string; @@ -23,7 +23,7 @@ interface ExtendedUser extends User { interface User { firstName: string; lastName: string; - }; + } const arrayOfNumbers: Immutable.ImmutableArray = Immutable.from([0, 2]); const user: Immutable.ImmutableObject = Immutable.from({ @@ -83,28 +83,31 @@ interface ExtendedUser extends User { }; // set: property name is strongly checked - const updatedUser: Immutable.ImmutableObject = immutableUser.set('firstName', 'Whirlwind'); + const updatedUser01: Immutable.ImmutableObject = immutableUser.set('firstName', 'Whirlwind'); + const updatedUser02: Immutable.ImmutableObject = immutableUser.set(data.propertyId, 'Whirlwind'); // setIn: property path is strongly checked for up to 5 arguments (helps with refactoring and intellisense) // but will fall back to any[] if there are dynamic arguments on the way - const updatedUser2: Immutable.ImmutableObject = immutableUserEx.setIn(['address', 'line1'], 'Small house'); - const updatedUser3: Immutable.ImmutableObject = immutableUserEx.setIn([ data.propertyId, 'line1' ], 'Small house'); + const updatedUser11: Immutable.ImmutableObject = immutableUserEx.setIn(['address', 'line1'], 'Small house'); + const updatedUser12: Immutable.ImmutableObject = immutableUserEx.setIn([ data.propertyId, 'line1' ], 'Small house'); // asMutable - const mutableUser1: User = immutableUser.asMutable(); - const mutableUser2: User = immutableUser.asMutable({ deep: true }); + const mutableUser21: User = immutableUser.asMutable(); + const mutableUser22: User = immutableUser.asMutable({ deep: true }); // merge: merged part is strongly checked as a deeply partial object const mergedUser: Immutable.ImmutableObject = immutableUserEx.merge({ address: { line1: 'Small house' }, firstName: 'Jack' }); // update: property name is strongly checked - const updatedUser4: Immutable.ImmutableObject = immutableUser.update('firstName', x => x.toLowerCase() + ' Whirlwind'); + const updatedUser41: Immutable.ImmutableObject = immutableUser.update('firstName', x => x.toLowerCase() + ' Whirlwind'); + // the type of the updated value must be explicity specified in case of fallback + const updatedUser42: Immutable.ImmutableObject = immutableUser.update(data.propertyId, x => x.toLowerCase() + ' Whirlwind'); // updateIn: property path is strongly checked for up to 5 arguments (helps with refactoring and intellisense) // but will fall back to any[] if there are dynamic arguments on the way - const updatedUser5: Immutable.ImmutableObject = immutableUserEx.updateIn([ 'address', 'line1' ], x => x.toLowerCase() + ' 43'); + const updatedUser51: Immutable.ImmutableObject = immutableUserEx.updateIn([ 'address', 'line1' ], x => x.toLowerCase() + ' 43'); // the type of the updated value must be explicity specified in case of fallback - const updatedUser6: Immutable.ImmutableObject = immutableUserEx.updateIn([ data.propertyId, 'line1' ], x => x.toLowerCase() + ' 43'); + const updatedUser52: Immutable.ImmutableObject = immutableUserEx.updateIn([ data.propertyId, 'line1' ], x => x.toLowerCase() + ' 43'); // without: the return type must be specified explicitly or it will be `any` const simpleUser1: Immutable.ImmutableObject = immutableUserEx.without('address'); diff --git a/types/seamless-immutable/tslint.json b/types/seamless-immutable/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/seamless-immutable/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }