Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Flow: Record: Fix created class types #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions dist/immutable.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -1132,22 +1132,20 @@ declare class Stack<+T> extends IndexedCollection<T> {
declare function Range(start?: number, end?: number, step?: number): IndexedSeq<number>;
declare function Repeat<T>(value: T, times?: number): IndexedSeq<T>;

declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordInstance);
declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordClass);
declare class Record {
static <Values>(spec: Values, name?: string): RecordClass<Values>;
constructor<Values>(spec: Values, name?: string): RecordClass<Values>;
static <Values>(spec: Values, name?: string): Class<RecordClass<Values>>;
constructor<Values>(spec: Values, name?: string): Class<RecordClass<Values>>;

static isRecord: typeof isRecord;

static getDescriptiveName(record: RecordInstance<*>): string;
static getDescriptiveName(record: RecordClass<*>): string;
}

declare interface RecordClass<T> {
(values: $Shape<T> | Iterable<[string, any]>): RecordInstance<T> & T;
new (values: $Shape<T> | Iterable<[string, any]>): RecordInstance<T> & T;
}
declare class RecordClass<T: Object> {
static (values?: $Shape<T> | Iterable<[string, any]>): RecordClass<T> & T;
constructor(values?: $Shape<T> | Iterable<[string, any]>): RecordClass<T> & T;

declare class RecordInstance<T: Object> {
size: number;

has(key: string): boolean;
Expand Down
16 changes: 7 additions & 9 deletions type-definitions/immutable.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -1132,22 +1132,20 @@ declare class Stack<+T> extends IndexedCollection<T> {
declare function Range(start?: number, end?: number, step?: number): IndexedSeq<number>;
declare function Repeat<T>(value: T, times?: number): IndexedSeq<T>;

declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordInstance);
declare function isRecord(maybeRecord: any): boolean %checks(maybeRecord instanceof RecordClass);
declare class Record {
static <Values>(spec: Values, name?: string): RecordClass<Values>;
constructor<Values>(spec: Values, name?: string): RecordClass<Values>;
static <Values>(spec: Values, name?: string): Class<RecordClass<Values>>;
constructor<Values>(spec: Values, name?: string): Class<RecordClass<Values>>;

static isRecord: typeof isRecord;

static getDescriptiveName(record: RecordInstance<*>): string;
static getDescriptiveName(record: RecordClass<*>): string;
}

declare interface RecordClass<T> {
(values: $Shape<T> | Iterable<[string, any]>): RecordInstance<T> & T;
new (values: $Shape<T> | Iterable<[string, any]>): RecordInstance<T> & T;
}
declare class RecordClass<T: Object> {
static (values?: $Shape<T> | Iterable<[string, any]>): RecordClass<T> & T;
constructor(values?: $Shape<T> | Iterable<[string, any]>): RecordClass<T> & T;

declare class RecordInstance<T: Object> {
size: number;

has(key: string): boolean;
Expand Down
6 changes: 6 additions & 0 deletions type-definitions/tests/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});

Expand Down