mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-11 10:59:55 +08:00
set/update fallbacks, tests, tslint coverage
This commit is contained in:
2
types/seamless-immutable/index.d.ts
vendored
2
types/seamless-immutable/index.d.ts
vendored
@@ -36,6 +36,7 @@ declare namespace SeamlessImmutable {
|
||||
|
||||
interface IImmutableObject<T> {
|
||||
set<K extends keyof T>(property: K, value: T[K]): ImmutableObject<T>;
|
||||
set<TValue>(property: string, value: TValue): ImmutableObject<T>;
|
||||
setIn<K extends keyof T>
|
||||
(propertyPath: [ K ], value: T[K]): ImmutableObject<T>;
|
||||
setIn<K extends keyof T, L extends keyof T[K]>
|
||||
@@ -54,6 +55,7 @@ declare namespace SeamlessImmutable {
|
||||
merge(part: DeepPartial<T>, config?: MergeConfig): ImmutableObject<T>;
|
||||
|
||||
update<K extends keyof T>(property: K, updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject<T>;
|
||||
update<TValue>(property: string, updaterFunction: (value: TValue, ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject<T>;
|
||||
updateIn<K extends keyof T>
|
||||
(propertyPath: [ K ], updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject<T>;
|
||||
updateIn<K extends keyof T, L extends keyof T[K]>
|
||||
|
||||
@@ -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<number> = Immutable.from([0, 2]);
|
||||
const user: Immutable.ImmutableObject<User> = Immutable.from({
|
||||
@@ -83,28 +83,31 @@ interface ExtendedUser extends User {
|
||||
};
|
||||
|
||||
// set: property name is strongly checked
|
||||
const updatedUser: Immutable.ImmutableObject<User> = immutableUser.set('firstName', 'Whirlwind');
|
||||
const updatedUser01: Immutable.ImmutableObject<User> = immutableUser.set('firstName', 'Whirlwind');
|
||||
const updatedUser02: Immutable.ImmutableObject<User> = 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<ExtendedUser> = immutableUserEx.setIn(['address', 'line1'], 'Small house');
|
||||
const updatedUser3: Immutable.ImmutableObject<ExtendedUser> = immutableUserEx.setIn([ data.propertyId, 'line1' ], 'Small house');
|
||||
const updatedUser11: Immutable.ImmutableObject<ExtendedUser> = immutableUserEx.setIn(['address', 'line1'], 'Small house');
|
||||
const updatedUser12: Immutable.ImmutableObject<ExtendedUser> = 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<User> = immutableUserEx.merge({ address: { line1: 'Small house' }, firstName: 'Jack' });
|
||||
|
||||
// update: property name is strongly checked
|
||||
const updatedUser4: Immutable.ImmutableObject<User> = immutableUser.update('firstName', x => x.toLowerCase() + ' Whirlwind');
|
||||
const updatedUser41: Immutable.ImmutableObject<User> = 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<User> = immutableUser.update<string>(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<User> = immutableUserEx.updateIn([ 'address', 'line1' ], x => x.toLowerCase() + ' 43');
|
||||
const updatedUser51: Immutable.ImmutableObject<User> = 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<User> = immutableUserEx.updateIn<string>([ data.propertyId, 'line1' ], x => x.toLowerCase() + ' 43');
|
||||
const updatedUser52: Immutable.ImmutableObject<User> = immutableUserEx.updateIn<string>([ data.propertyId, 'line1' ], x => x.toLowerCase() + ' 43');
|
||||
|
||||
// without: the return type must be specified explicitly or it will be `any`
|
||||
const simpleUser1: Immutable.ImmutableObject<any> = immutableUserEx.without('address');
|
||||
|
||||
1
types/seamless-immutable/tslint.json
Normal file
1
types/seamless-immutable/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user