diff --git a/lib/core.js b/lib/core.js index 2f2dc51b067..5d77d6c031f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -21,7 +21,7 @@ declare function decodeURIComponent(encodedURIComponent: string): string; declare function encodeURI(uri: string): string; declare function encodeURIComponent(uriComponent: string): string; -type PropertyDescriptor = { +type ContraPropertyDescriptor = { enumerable?: boolean, configurable?: boolean, writable?: boolean, @@ -31,7 +31,33 @@ type PropertyDescriptor = { ... }; -type PropertyDescriptorMap = { [s: string]: PropertyDescriptor, ... } +type CoPropertyDescriptor = { + 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; +} + +type CoPropertyDescriptorMap = { + [s: string]: CoPropertyDescriptor; +} type $NotNullOrVoid = | number @@ -48,9 +74,9 @@ declare class Object { static (o: string): String; static (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(o: any, p: any, attributes: PropertyDescriptor): any; + static create(o: any, properties?: ContraPropertyDescriptorMap): any; // compiler magic + static defineProperties(o: any, properties: ContraPropertyDescriptorMap): any; + static defineProperty(o: any, p: any, attributes: ContraPropertyDescriptor): any; static entries(object: $NotNullOrVoid): Array<[string, mixed]>; static freeze(o: T): T; static fromEntries(entries: Iterable<[K, V] | { @@ -59,8 +85,8 @@ declare class Object { ... }>): { [K]: V, ... }; - static getOwnPropertyDescriptor(o: $NotNullOrVoid, p: any): PropertyDescriptor | void; - static getOwnPropertyDescriptors(o: {...}): PropertyDescriptorMap; + static getOwnPropertyDescriptor(o: $NotNullOrVoid, p: any): CoPropertyDescriptor | 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; @@ -849,8 +875,8 @@ type Proxy$traps = { setPrototypeOf?: (target: T, prototype: {[any] : any, ...} | null) => boolean, isExtensible?: (target: T) => boolean, preventExtensions?: (target: T) => boolean, - getOwnPropertyDescriptor?: (target: T, property: string) => void | PropertyDescriptor, - defineProperty?: (target: T, property: string, descriptor: PropertyDescriptor) => boolean, + getOwnPropertyDescriptor?: (target: T, property: string) => void | CoPropertyDescriptor, + defineProperty?: (target: T, property: string, descriptor: ContraPropertyDescriptor) => boolean, has?: (target: T, key: string) => boolean, get?: (target: T, property: string, receiver: Proxy) => any, set?: (target: T, property: string, value: any, receiver: Proxy) => boolean,