From fb798e5fabb9cd792dc27c95ae3e963d02964d6d Mon Sep 17 00:00:00 2001 From: Stepan Burguchev Date: Sun, 9 Jul 2017 18:07:06 +0300 Subject: [PATCH] final polishing --- types/seamless-immutable/index.d.ts | 46 +++++++++++-------- .../seamless-immutable-tests.ts | 24 +++++----- types/seamless-immutable/tsconfig.json | 2 +- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/types/seamless-immutable/index.d.ts b/types/seamless-immutable/index.d.ts index a121e584f1..761f6e460c 100644 --- a/types/seamless-immutable/index.d.ts +++ b/types/seamless-immutable/index.d.ts @@ -1,7 +1,9 @@ // Type definitions for Seamless-immutable 6.1.3 // Project: https://github.com/rtfeldman/seamless-immutable // Definitions by: alex3165 +// Stepan Burguchev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // This project is licensed under the MIT license. // Copyrights are respective of each contributor listed at the beginning of each definition file. @@ -32,48 +34,54 @@ declare namespace SeamlessImmutable { deep: boolean; } - export interface ImmutableObject { - set(property: K, value: T[K]): T & ImmutableObject; + interface IImmutableObject { + set(property: K, value: T[K]): ImmutableObject; setIn - (propertyPath: [ K ], value: T[K]): T & ImmutableObject; + (propertyPath: [ K ], value: T[K]): ImmutableObject; setIn - (propertyPath: [ K, L ], value: T[K][L]): T & ImmutableObject; + (propertyPath: [ K, L ], value: T[K][L]): ImmutableObject; setIn - (propertyPath: [ K, L, M ], value: T[K][L][M]): T & ImmutableObject; + (propertyPath: [ K, L, M ], value: T[K][L][M]): ImmutableObject; setIn - (propertyPath: [ K, L, M, N ], value: T[K][L][M][N]): T & ImmutableObject; + (propertyPath: [ K, L, M, N ], value: T[K][L][M][N]): ImmutableObject; + setIn + (propertyPath: [ K, L, M, N, O ], value: T[K][L][M][N][O]): ImmutableObject; asMutable(): T; asMutable(opts: AsMutableOptions): T; - merge(part: DeepPartial, config?: MergeConfig): T & ImmutableObject; + merge(part: DeepPartial, config?: MergeConfig): ImmutableObject; - update(property: K, updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): T & ImmutableObject; + update(property: K, updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; updateIn - (propertyPath: [ K ], updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): T & ImmutableObject; + (propertyPath: [ K ], updaterFunction: (value: T[K], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; updateIn - (propertyPath: [ K, L ], updaterFunction: (value: T[K][L], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): T & ImmutableObject; + (propertyPath: [ K, L ], updaterFunction: (value: T[K][L], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; updateIn - (propertyPath: [ K, L, M ], updaterFunction: (value: T[K][L][M], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): T & ImmutableObject; + (propertyPath: [ K, L, M ], updaterFunction: (value: T[K][L][M], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; updateIn - (propertyPath: [ K, L, M, N ], updaterFunction: (value: T[K][L][M][N], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): T & ImmutableObject; + (propertyPath: [ K, L, M, N ], updaterFunction: (value: T[K][L][M][N], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; + updateIn + (propertyPath: [ K, L, M, N, O ], updaterFunction: (value: T[K][L][M][N][O], ...additionalParameters: any[]) => any, ...additionalArguments: any[]): ImmutableObject; - without(property: keyof T): TTarget & ImmutableObject; - without(...properties: Array): TTarget & ImmutableObject; - without(filter: (value: T[keyof T], key: keyof T) => boolean): TTarget & ImmutableObject; + without(property: keyof T): ImmutableObject; + without(...properties: Array): ImmutableObject; + without(filter: (value: T[keyof T], key: keyof T) => boolean): ImmutableObject; } - export interface ImmutableArray { + interface IImmutableArray { asMutable(): Array; asMutable(opts: AsMutableOptions): Array; asObject(toKeyValue: (item: T) => [string, any]): ImmutableObject; - flatMap(mapFunction: (item: T) => Array): TTarget[] & ImmutableArray; + flatMap(mapFunction: (item: T) => Array): ImmutableArray; } + export type ImmutableObject = T & IImmutableObject; + export type ImmutableArray = Array & IImmutableArray; export type Immutable = ImmutableObject | ImmutableArray; - export function from(obj: Array, options?: Options): Array & ImmutableArray; - export function from(obj: T, options?: Options): T & ImmutableObject; + export function from(obj: Array, options?: Options): ImmutableArray; + export function from(obj: T, options?: Options): ImmutableObject; export function isImmutable(target: any): boolean; export function ImmutableError(message: string): Error; diff --git a/types/seamless-immutable/seamless-immutable-tests.ts b/types/seamless-immutable/seamless-immutable-tests.ts index e5f7411d55..1c5beffad6 100644 --- a/types/seamless-immutable/seamless-immutable-tests.ts +++ b/types/seamless-immutable/seamless-immutable-tests.ts @@ -25,8 +25,8 @@ interface ExtendedUser extends User { lastName: string; }; - const arrayOfNumbers: number[] & Immutable.ImmutableArray = Immutable.from([0, 2]); - const user: User & Immutable.ImmutableObject = Immutable.from({ + const arrayOfNumbers: Immutable.ImmutableArray = Immutable.from([0, 2]); + const user: Immutable.ImmutableObject = Immutable.from({ firstName: 'Angry', lastName: 'Monkey' }); @@ -45,14 +45,14 @@ interface ExtendedUser extends User { // Instance syntax: immutable array // --------------------------------------------------------------- { - const array: User[] & Immutable.ImmutableArray = Immutable.from([ { firstName: 'Angry', lastName: 'Monkey' } ]); + const array: Immutable.ImmutableArray = Immutable.from([ { firstName: 'Angry', lastName: 'Monkey' } ]); // asMutable const mutableArray1: User[] = array.asMutable(); const mutableArray2: User[] = array.asMutable({ deep: true }); // flatMap - const flatMappedArray: User[] & Immutable.ImmutableArray = array.flatMap((value: User) => + const flatMappedArray: Immutable.ImmutableArray = array.flatMap((value: User) => [value, value] ); @@ -78,26 +78,26 @@ interface ExtendedUser extends User { }); // set: property name is strongly checked - const updatedUser: User & Immutable.ImmutableObject = immutableUser.set('firstName', 'Whirlwind'); + const updatedUser: Immutable.ImmutableObject = immutableUser.set('firstName', 'Whirlwind'); - // setIn: property path is strongly checked for up to 4 arguments - const updatedUser2: ExtendedUser & Immutable.ImmutableObject = immutableUserEx.setIn(['address', 'line1'], 'Small house'); + // setIn: property path is strongly checked for up to 5 arguments + const updatedUser2: Immutable.ImmutableObject = immutableUserEx.setIn(['address', 'line1'], 'Small house'); // asMutable const mutableUser1: User = immutableUser.asMutable(); const mutableUser2: User = immutableUser.asMutable({ deep: true }); // merge: merged part is strongly checked as a deeply partial object - const mergedUser: User & Immutable.ImmutableObject = immutableUserEx.merge({ address: { line1: 'Small house' }, firstName: 'Jack' }); + const mergedUser: Immutable.ImmutableObject = immutableUserEx.merge({ address: { line1: 'Small house' }, firstName: 'Jack' }); // update: property name is strongly checked - const updatedUser3: User & Immutable.ImmutableObject = immutableUser.update('firstName', x => x.toLowerCase() + ' Whirlwind'); + const updatedUser3: Immutable.ImmutableObject = immutableUser.update('firstName', x => x.toLowerCase() + ' Whirlwind'); - // updateIn: property path is strongly checked for up to 4 arguments - const updatedUser4: User & Immutable.ImmutableObject = immutableUserEx.updateIn([ 'address', 'line1' ], x => x.toLowerCase() + ' 43'); + // updateIn: property path is strongly checked for up to 5 arguments + const updatedUser4: Immutable.ImmutableObject = immutableUserEx.updateIn([ 'address', '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'); - const simpleUser2: User & Immutable.ImmutableObject = immutableUserEx.without('address'); + const simpleUser2: Immutable.ImmutableObject = immutableUserEx.without('address'); const simpleUser3: Immutable.ImmutableObject = immutableUserEx.without('firstName', 'lastName'); } diff --git a/types/seamless-immutable/tsconfig.json b/types/seamless-immutable/tsconfig.json index 6ca679e6d8..8e2483cd41 100644 --- a/types/seamless-immutable/tsconfig.json +++ b/types/seamless-immutable/tsconfig.json @@ -19,4 +19,4 @@ "index.d.ts", "seamless-immutable-tests.ts" ] -} \ No newline at end of file +}