seamless-immutable - add static asMutable method to type (#44284)

* seamless-immutable - add static asMutable method to type

* remove inadvertent seamless tgz
This commit is contained in:
Frak Lopez 2020-05-13 08:28:36 -07:00 committed by GitHub
parent eb7ec52c01
commit 237c034141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -175,6 +175,14 @@ declare namespace SeamlessImmutable {
function ImmutableError(message: string): Error;
function replace<T, S>(obj: Immutable<T>, valueObj: S, options?: ReplaceConfig): Immutable<S>;
function asMutable<T>(obj: T[] | ImmutableArray<T>, opts?: AsMutableOptions<false>): T[];
function asMutable<T>(obj: T[] | ImmutableArray<T>, opts: AsMutableOptions<true>): T[];
function asMutable<T>(obj: T[] | ImmutableArray<T>, opts: AsMutableOptions): T[] | Array<Immutable<T>>;
function asMutable<T>(obj: T | ImmutableObject<T>, opts?: AsMutableOptions<false>): { [K in keyof T]: Immutable<T[K]> };
function asMutable<T>(obj: T | ImmutableObject<T>, opts: AsMutableOptions<true>): T;
function asMutable<T>(obj: T | ImmutableObject<T>, opts: AsMutableOptions): T | { [K in keyof T]: Immutable<T[K]> };
}
declare function SeamlessImmutable<T>(obj: T, options?: SeamlessImmutable.Options): SeamlessImmutable.Immutable<T>;

View File

@ -86,8 +86,22 @@ interface NonDeepMutableExtendedUser {
firstName: 'Angry',
lastName: 'Monkey'
});
const users: Immutable.Immutable<string[]> = Immutable.from(['Angry']);
const replacedUser01 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' });
const replacedUser02 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' }, { deep: true });
// $ExpectError
user1.firstName = 'Untouchable';
// asMutable on object
const mutableObject = Immutable.asMutable(user1);
mutableObject.firstName = 'Sedated';
// $ExpectError
users.push('Super');
// asMutable on array
const mutableArray = Immutable.asMutable(users);
mutableArray.push('Super');
}
//