Skip to content

Commit

Permalink
Update core.js types: add PropertyDescriptor, update Object, Function…
Browse files Browse the repository at this point in the history
…, Proxy and setTimeout/setInterval
  • Loading branch information
apsavin committed Oct 10, 2017
1 parent 13fb896 commit f805805
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 161 deletions.
36 changes: 25 additions & 11 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<*>;
}

// 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(o: any, p: any, attributes: PropertyDescriptor<*>): any;
static entries(object: any): Array<[string, mixed]>;
static freeze<T>(o: T): T;
static getOwnPropertyDescriptor(o: any, p: any): any;
static getOwnPropertyDescriptor(o: any, p: any): PropertyDescriptor<*> | void;
static getOwnPropertyNames(o: any): Array<string>;
static getOwnPropertySymbols(o: any): Symbol[];
static getPrototypeOf: Object$GetPrototypeOf;
Expand All @@ -43,8 +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 preventExtensions<T>(o: T): T;
static seal<T>(o: T): T;
static setPrototypeOf(o: any, proto: ?Object): bool;
static values(object: any): Array<mixed>;
hasOwnProperty(prop: any): boolean;
Expand Down Expand Up @@ -94,6 +107,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 @@ -729,8 +743,8 @@ declare function unescape(str: string): string;

declare function clearInterval(intervalId?: number): void;
declare function clearTimeout(timeoutId?: any): void;
declare function setTimeout(callback: any, ms?: number, ...args: Array<any>): number;
declare function setInterval(callback: any, ms?: number, ...args: Array<any>): number;
declare function setTimeout(callback: Function, ms?: number, ...args: Array<any>): number;
declare function setInterval(callback: Function, ms?: number, ...args: Array<any>): number;

/* Reflect API */

Expand All @@ -757,8 +771,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?: (target: T, property: string) => void | PropertyDescriptor<*>;
defineProperty?: (target: T, property: string, descriptor: PropertyDescriptor<*>) => 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
8 changes: 4 additions & 4 deletions tests/arrows/arrows.exp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Error: advanced_arrows.js:11
Error: arrows.js:7
7: images = images.sort((a, b) => (a.width - b.width) + "");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function. This type is incompatible with the expected param type of
269: sort(compareFn?: (a: T, b: T) => number): Array<T>;
^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: <BUILTINS>/core.js:269
283: sort(compareFn?: (a: T, b: T) => number): Array<T>;
^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: <BUILTINS>/core.js:283
This parameter is incompatible:
7: images = images.sort((a, b) => (a.width - b.width) + "");
^^^^^^^^^^^^^^^^^^^^^^^^ string. This type is incompatible with
269: sort(compareFn?: (a: T, b: T) => number): Array<T>;
^^^^^^ number. See lib: <BUILTINS>/core.js:269
283: sort(compareFn?: (a: T, b: T) => number): Array<T>;
^^^^^^ number. See lib: <BUILTINS>/core.js:283


Found 3 errors
Loading

0 comments on commit f805805

Please sign in to comment.