Skip to content
44 changes: 35 additions & 9 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare function decodeURIComponent(encodedURIComponent: string): string;
declare function encodeURI(uri: string): string;
declare function encodeURIComponent(uriComponent: string): string;

type PropertyDescriptor<T> = {
type ContraPropertyDescriptor<T> = {
enumerable?: boolean,
configurable?: boolean,
writable?: boolean,
Expand All @@ -31,7 +31,33 @@ type PropertyDescriptor<T> = {
...
};

type PropertyDescriptorMap = { [s: string]: PropertyDescriptor<any>, ... }
type CoPropertyDescriptor<T> = {
enumerable: boolean;
configurable: boolean;
writable: boolean;
value: T;
} | {
enumerable: boolean;
configurable: boolean;
get: () => T;
set: (value: T) => void;
} | {
enumerable: boolean;
configurable: boolean;
get: () => T;
} | {
enumerable: boolean;
configurable: boolean;
set: (value: T) => void;
};

type ContraPropertyDescriptorMap = {
[s: string]: ContraPropertyDescriptor<any>;
}

type CoPropertyDescriptorMap = {
[s: string]: CoPropertyDescriptor<any>;
}

type $NotNullOrVoid =
| number
Expand All @@ -48,9 +74,9 @@ declare class Object {
static (o: string): String;
static <T>(o: T): T;
static assign: Object$Assign;
static create(o: any, properties?: PropertyDescriptorMap): any; // compiler magic
static defineProperties(o: any, properties: PropertyDescriptorMap): any;
static defineProperty<T>(o: any, p: any, attributes: PropertyDescriptor<T>): any;
static create(o: any, properties?: ContraPropertyDescriptorMap): any; // compiler magic
static defineProperties(o: any, properties: ContraPropertyDescriptorMap): any;
static defineProperty<T>(o: any, p: any, attributes: ContraPropertyDescriptor<T>): any;
static entries(object: $NotNullOrVoid): Array<[string, mixed]>;
static freeze<T>(o: T): T;
static fromEntries<K, V>(entries: Iterable<[K, V] | {
Expand All @@ -59,8 +85,8 @@ declare class Object {
...
}>): { [K]: V, ... };

static getOwnPropertyDescriptor<T>(o: $NotNullOrVoid, p: any): PropertyDescriptor<T> | void;
static getOwnPropertyDescriptors(o: {...}): PropertyDescriptorMap;
static getOwnPropertyDescriptor<T>(o: $NotNullOrVoid, p: any): CoPropertyDescriptor<T> | void;
static getOwnPropertyDescriptors(o: {...}): CoPropertyDescriptorMap;
// This is documentation only. Object.getOwnPropertyNames is implemented in OCaml code
// https://github.com/facebook/flow/blob/8ac01bc604a6827e6ee9a71b197bb974f8080049/src/typing/statement.ml#L6308
static getOwnPropertyNames(o: $NotNullOrVoid): Array<string>;
Expand Down Expand Up @@ -849,8 +875,8 @@ type Proxy$traps<T> = {
setPrototypeOf?: (target: T, prototype: {[any] : any, ...} | null) => boolean,
isExtensible?: (target: T) => boolean,
preventExtensions?: (target: T) => boolean,
getOwnPropertyDescriptor?: (target: T, property: string) => void | PropertyDescriptor<T>,
defineProperty?: (target: T, property: string, descriptor: PropertyDescriptor<T>) => boolean,
getOwnPropertyDescriptor?: (target: T, property: string) => void | CoPropertyDescriptor<T>,
defineProperty?: (target: T, property: string, descriptor: ContraPropertyDescriptor<T>) => boolean,
has?: (target: T, key: string) => boolean,
get?: (target: T, property: string, receiver: Proxy<T>) => any,
set?: (target: T, property: string, value: any, receiver: Proxy<T>) => boolean,
Expand Down