Skip to content

Commit

Permalink
[PR] Update core.js types
Browse files Browse the repository at this point in the history
Summary:
Add PropertyDescriptor, update Object, Function, Proxy and setTimeout/setInterval
Closes #5067

Reviewed By: calebmer

Differential Revision: D6070703

Pulled By: gabelevi

fbshipit-source-id: 4989cb6e7987118a54874db4eb16e21905d763f1
  • Loading branch information
apsavin authored and facebook-github-bot committed Feb 16, 2018
1 parent 3209a4b commit 8e8f9ff
Show file tree
Hide file tree
Showing 32 changed files with 863 additions and 850 deletions.
33 changes: 23 additions & 10 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
/* JS primitives
cf. http://typescript.codeplex.com/sourcecontrol/latest#typings/lib.d.ts
cf. https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts
*/

declare var NaN: number;
Expand All @@ -21,6 +21,19 @@ declare function decodeURIComponent(encodedURIComponent: string): string;
declare function encodeURI(uri: string): string;
declare function encodeURIComponent(uriComponent: string): string;

type PropertyDescriptor<T> = {
enumerable?: boolean;
configurable?: boolean;
writable?: boolean;
value?: T;
get?: () => T;
set?: (value: T) => void;
};

type PropertyDescriptorMap = {
[s: string]: PropertyDescriptor<any>;
}

// TODO: instance
declare class Object {
static (o: ?void): {[key: any]: any};
Expand All @@ -29,12 +42,12 @@ declare class Object {
static (o: string): String;
static <T: Object>(o: T): T;
static assign: Object$Assign;
static create(o: any, properties?: any): any; // compiler magic
static defineProperties(o: any, properties: any): any;
static defineProperty(o: any, p: any, attributes: any): any;
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 entries(object: any): Array<[string, mixed]>;
static freeze<T>(o: T): T;
static getOwnPropertyDescriptor(o: any, p: any): any;
static getOwnPropertyDescriptor<T>(o: any, p: any): PropertyDescriptor<T> | void;
static getOwnPropertyNames(o: any): Array<string>;
static getOwnPropertySymbols(o: any): Symbol[];
static getPrototypeOf: Object$GetPrototypeOf;
Expand All @@ -43,9 +56,8 @@ declare class Object {
static isFrozen(o: any): boolean;
static isSealed(o: any): boolean;
static keys(o: any): Array<string>;
static preventExtensions(o: any): any;
static seal(o: any): any;
static setPrototypeOf(o: any, proto: ?Object): any;
static preventExtensions<T>(o: T): T;
static seal<T>(o: T): T;
static values(object: any): Array<mixed>;
hasOwnProperty(prop: any): boolean;
isPrototypeOf(o: any): boolean;
Expand Down Expand Up @@ -94,6 +106,7 @@ declare class Function {
apply: Function$Prototype$Apply; // (thisArg: any, argArray?: any) => any
bind: Function$Prototype$Bind; // (thisArg: any, ...argArray: Array<any>) => any;
call: Function$Prototype$Call; // (thisArg: any, ...argArray: Array<any>) => any
toString(): string;
arguments: any;
caller: Function | null;
length: number;
Expand Down Expand Up @@ -767,8 +780,8 @@ type Proxy$traps<T> = {
setPrototypeOf?: (target: T, prototype: Object|null) => boolean;
isExtensible?: (target: T) => boolean;
preventExtensions?: (target: T) => boolean;
getOwnPropertyDescriptor?: (target: T, property: string) => void | Object;
defineProperty?: (target: T, property: string, descriptor: Object) => boolean;
getOwnPropertyDescriptor?: <T>(target: T, property: string) => void | PropertyDescriptor<T>;
defineProperty?: <T>(target: T, property: string, descriptor: PropertyDescriptor<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
4 changes: 2 additions & 2 deletions newtests/array_literal_tuple_spread/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ export default suite(({addFile, addFiles, addCode}) => [
3: const arr: Array<number> = [..."hello"];
^^^^^^^^^^^^ Cannot assign array literal to \`arr\` because string [1] is incompatible with number [2] in array element.
References:
288: @@iterator(): Iterator<string>;
^^^^^^ [1]. See lib: [LIB] core.js:288
301: @@iterator(): Iterator<string>;
^^^^^^ [1]. See lib: [LIB] core.js:301
3: const arr: Array<number> = [..."hello"];
^^^^^^ [2]
`,
Expand Down
Loading

0 comments on commit 8e8f9ff

Please sign in to comment.