immutable-class
Advanced tools
Comparing version 0.9.8 to 0.9.9
@@ -10,4 +10,6 @@ export declare type Validator = (x: any) => void; | ||
}; | ||
export interface Property { | ||
name: string; | ||
export interface Property<T extends { | ||
[key: string]: any; | ||
} = any> { | ||
name: keyof T; | ||
defaultValue?: any; | ||
@@ -46,3 +48,3 @@ possibleValues?: any[]; | ||
export declare abstract class BaseImmutable<ValueType, JSType> implements ImmutableInstanceType<ValueType, JSType> { | ||
static jsToValue(properties: Property[], js: any, backCompats?: BackCompat[], context?: Record<string, any>): any; | ||
static jsToValue<T = any>(properties: Property<T>[], js: any, backCompats?: BackCompat[], context?: Record<string, any>): any; | ||
static finalize(ClassFn: ClassFnType): void; | ||
@@ -55,5 +57,5 @@ static ensure: { | ||
constructor(value: ValueType); | ||
ownProperties(): Property[]; | ||
findOwnProperty(propName: string): Property | undefined; | ||
hasProperty(propName: string): boolean; | ||
ownProperties(): Property<ValueType>[]; | ||
findOwnProperty(propName: keyof ValueType): Property | undefined; | ||
hasProperty(propName: keyof ValueType): boolean; | ||
valueOf(): ValueType; | ||
@@ -66,7 +68,7 @@ toJS(): JSType; | ||
equivalent(other: BaseImmutable<ValueType, JSType>): boolean; | ||
get(propName: string): any; | ||
change(propName: string, newValue: any): this; | ||
changeMany(properties: Record<string, any>): this; | ||
get<T extends keyof ValueType>(propName: T): ValueType[T]; | ||
change<T extends keyof ValueType>(propName: T, newValue: ValueType[T]): this; | ||
changeMany(properties: Partial<ValueType>): this; | ||
deepChange(propName: string, newValue: any): this; | ||
deepGet(propName: string): any; | ||
} |
@@ -196,2 +196,9 @@ "use strict"; | ||
}); | ||
it('works with types', function () { | ||
var car = car_mock_1.Car.fromJS({ | ||
fuel: 'electric', | ||
name: 'ford', | ||
}); | ||
car.change('owners', ['foo']); | ||
}); | ||
}); |
@@ -21,2 +21,4 @@ import { BackCompat, BaseImmutable, Property } from './base-immutable'; | ||
createdOn?: Date; | ||
owners?: string[]; | ||
driver?: Driver; | ||
} | ||
@@ -30,5 +32,7 @@ export interface CarJS { | ||
createdOn?: Date | string; | ||
owners?: string[]; | ||
driver?: DriverJS; | ||
} | ||
export declare class Car extends BaseImmutable<CarValue, CarJS> { | ||
static PROPERTIES: Property[]; | ||
static PROPERTIES: Property<CarValue>[]; | ||
static BACK_COMPATS: BackCompat[]; | ||
@@ -35,0 +39,0 @@ static isCar(car: Car): boolean; |
{ | ||
"name": "immutable-class", | ||
"version": "0.9.8", | ||
"version": "0.9.9", | ||
"description": "A template for creating immutable classes", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92360
32
1959