Skip to content
59 changes: 47 additions & 12 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,52 @@ 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;
value?: T;
get?: () => T;
set?: (value: T) => void;
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 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 PropertyDescriptorMap = {
[s: string]: PropertyDescriptor<any>;
type ContraPropertyDescriptorMap = {
[s: string]: ContraPropertyDescriptor<any>;
}

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

// TODO: instance
Expand All @@ -42,12 +77,12 @@ declare class Object {
static (o: string): String;
static <T: Object>(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: any): Array<[string, mixed]>;
static freeze<T>(o: T): T;
static getOwnPropertyDescriptor<T>(o: any, p: any): PropertyDescriptor<T> | void;
static getOwnPropertyDescriptor<T>(o: any, p: any): CoPropertyDescriptor<T> | void;
static getOwnPropertyNames(o: any): Array<string>;
static getOwnPropertySymbols(o: any): Symbol[];
static getPrototypeOf: Object$GetPrototypeOf;
Expand Down Expand Up @@ -760,8 +795,8 @@ type Proxy$traps<T> = {
setPrototypeOf?: (target: T, prototype: Object|null) => boolean;
isExtensible?: (target: T) => boolean;
preventExtensions?: (target: T) => boolean;
getOwnPropertyDescriptor?: <T>(target: T, property: string) => void | PropertyDescriptor<T>;
defineProperty?: <T>(target: T, property: string, descriptor: PropertyDescriptor<T>) => boolean;
getOwnPropertyDescriptor?: <T>(target: T, property: string) => void | CoPropertyDescriptor<T>;
defineProperty?: <T>(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