mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 18:43:21 +08:00
Merge pull request #26693 from deepfunc/master
seamless-immutable add method: 'replace' definition
This commit is contained in:
8
types/seamless-immutable/index.d.ts
vendored
8
types/seamless-immutable/index.d.ts
vendored
@@ -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<K extends keyof T>(property: K): ImmutableObject<T>;
|
||||
without<K extends keyof T>(...properties: K[]): ImmutableObject<T>;
|
||||
without<K extends keyof T>(filter: (value: T[K], key: K) => boolean): ImmutableObject<T>;
|
||||
|
||||
replace<S>(valueObj: S, options?: ReplaceConfig): ImmutableObject<S>;
|
||||
}
|
||||
|
||||
interface ImmutableArrayMixin<T> {
|
||||
@@ -92,6 +98,8 @@ declare namespace SeamlessImmutable {
|
||||
|
||||
function isImmutable(target: any): boolean;
|
||||
function ImmutableError(message: string): Error;
|
||||
|
||||
function replace<T, S>(obj: ImmutableObject<T>, valueObj: S, options?: ReplaceConfig): ImmutableObject<S>;
|
||||
}
|
||||
|
||||
declare function SeamlessImmutable<T>(obj: T[], options?: SeamlessImmutable.Options): SeamlessImmutable.ImmutableArray<T>;
|
||||
|
||||
@@ -44,6 +44,12 @@ interface ExtendedUser extends User {
|
||||
|
||||
{
|
||||
const isImmutable: boolean = Immutable.isImmutable(Immutable.from([0, 2]));
|
||||
const user1: Immutable.ImmutableObject<User> = 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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user