diff --git a/dist/immutable.js.flow b/dist/immutable.js.flow index 7d6bf441e7..d979d3b3d3 100644 --- a/dist/immutable.js.flow +++ b/dist/immutable.js.flow @@ -1132,22 +1132,20 @@ declare class Stack<+T> extends IndexedCollection { declare function Range(start?: number, end?: number, step?: number): IndexedSeq; declare function Repeat(value: T, times?: number): IndexedSeq; -declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordInstance); +declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordClass); declare class Record { - static (spec: Values, name?: string): RecordClass; - constructor(spec: Values, name?: string): RecordClass; + static (spec: Values, name?: string): Class>; + constructor(spec: Values, name?: string): Class>; static isRecord: typeof isRecord; - static getDescriptiveName(record: RecordInstance<*>): string; + static getDescriptiveName(record: RecordClass<*>): string; } -declare interface RecordClass { - (values: $Shape | Iterable<[string, any]>): RecordInstance & T; - new (values: $Shape | Iterable<[string, any]>): RecordInstance & T; -} +declare class RecordClass { + static (values?: $Shape | Iterable<[string, any]>): RecordClass & T; + constructor(values?: $Shape | Iterable<[string, any]>): RecordClass & T; -declare class RecordInstance { size: number; has(key: string): boolean; diff --git a/type-definitions/immutable.js.flow b/type-definitions/immutable.js.flow index 7d6bf441e7..d979d3b3d3 100644 --- a/type-definitions/immutable.js.flow +++ b/type-definitions/immutable.js.flow @@ -1132,22 +1132,20 @@ declare class Stack<+T> extends IndexedCollection { declare function Range(start?: number, end?: number, step?: number): IndexedSeq; declare function Repeat(value: T, times?: number): IndexedSeq; -declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordInstance); +declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordClass); declare class Record { - static (spec: Values, name?: string): RecordClass; - constructor(spec: Values, name?: string): RecordClass; + static (spec: Values, name?: string): Class>; + constructor(spec: Values, name?: string): Class>; static isRecord: typeof isRecord; - static getDescriptiveName(record: RecordInstance<*>): string; + static getDescriptiveName(record: RecordClass<*>): string; } -declare interface RecordClass { - (values: $Shape | Iterable<[string, any]>): RecordInstance & T; - new (values: $Shape | Iterable<[string, any]>): RecordInstance & T; -} +declare class RecordClass { + static (values?: $Shape | Iterable<[string, any]>): RecordClass & T; + constructor(values?: $Shape | Iterable<[string, any]>): RecordClass & T; -declare class RecordInstance { size: number; has(key: string): boolean; diff --git a/type-definitions/tests/record.js b/type-definitions/tests/record.js index 725832c758..d569c5661b 100644 --- a/type-definitions/tests/record.js +++ b/type-definitions/tests/record.js @@ -9,13 +9,19 @@ import { Record } from '../../'; const Point2 = Record({x:0, y:0}); const Point3 = Record({x:0, y:0, z:0}); +const PointNew = new Record({x:0, y:0}); const GeoPoint = Record({lat:(null: ?number), lon:(null: ?number)}); let origin2 = Point2({}); let origin3 = Point3({}); +let originNew = new PointNew(); let geo = GeoPoint({lat:34}); // $ExpectError const mistake = Point2({x:'string'}); +// $ExpectError - 'new Record' instantiated with invalid type +const mistakeNewRecord = PointNew({x:'string'}); +// $ExpectError - 'Record' instantiated with invalid type using 'new' +const mistakeNewInstance = new Point2({x:'string'}); origin3 = GeoPoint({lat:34}) geo = Point3({});