From 6f9c8eab6ed8451765eee36dfdb774cf9ecd011e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Fri, 21 Apr 2017 18:30:36 +0200 Subject: [PATCH 1/9] added import of definition file in test --- types/es6-shim/es6-shim-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/es6-shim/es6-shim-tests.ts b/types/es6-shim/es6-shim-tests.ts index ed89d2ac35..b8834d3ab7 100644 --- a/types/es6-shim/es6-shim-tests.ts +++ b/types/es6-shim/es6-shim-tests.ts @@ -1,4 +1,4 @@ - +import './index' interface Point { x: number; y: number; } interface Point3D extends Point { z: number; } @@ -219,4 +219,4 @@ b = Reflect.preventExtensions(a); b = Reflect.set(a, s, a, a); b = Reflect.set(a, i, a, a); b = Reflect.set(a, sym, a, a); -b = Reflect.setPrototypeOf(a, a); \ No newline at end of file +b = Reflect.setPrototypeOf(a, a); From adc61a210d1c86a32f3d824f6d6386f6eb42882d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Fri, 21 Apr 2017 18:37:45 +0200 Subject: [PATCH 2/9] Fix "error TS2304: Cannot find name 'object'." with tsc 2.0.10 --- types/es6-shim/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/es6-shim/index.d.ts b/types/es6-shim/index.d.ts index 483f4357e0..179313246f 100644 --- a/types/es6-shim/index.d.ts +++ b/types/es6-shim/index.d.ts @@ -594,7 +594,7 @@ interface SetConstructor { declare var Set: SetConstructor; -interface WeakMap { +interface WeakMap { delete(key: K): boolean; get(key: K): V; has(key: K): boolean; @@ -602,8 +602,8 @@ interface WeakMap { } interface WeakMapConstructor { - new (): WeakMap; - new (iterable: IterableShim<[K, V]>): WeakMap; + new (): WeakMap; + new (iterable: IterableShim<[K, V]>): WeakMap; prototype: WeakMap; } From 316eb32560c7e0b2f2e9f536733e8c4c3b22456a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Fri, 21 Apr 2017 18:43:01 +0200 Subject: [PATCH 3/9] (Weak)Map.get(key) may return undefined - Enabled strictNullChecks - Intialized variables in test where needed --- types/es6-shim/es6-shim-tests.ts | 50 +++++++++++++++++--------------- types/es6-shim/index.d.ts | 4 +-- types/es6-shim/tsconfig.json | 4 +-- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/types/es6-shim/es6-shim-tests.ts b/types/es6-shim/es6-shim-tests.ts index b8834d3ab7..60a0e9fb4b 100644 --- a/types/es6-shim/es6-shim-tests.ts +++ b/types/es6-shim/es6-shim-tests.ts @@ -4,28 +4,30 @@ interface Point { x: number; y: number; } interface Point3D extends Point { z: number; } let a: any; -let s: string; +let s: string = ''; let i: number; let b: boolean; -let f: () => void; +let f: () => void = () => {}; let o: Object; -let r: RegExp; -let sym: symbol; -let e: Error; +let r: RegExp = /a/; +let sym: symbol = {} as symbol; +let e: Error = new Error(); let date: Date; let key: PropertyKey; -let point: Point; -let point3d: Point3D; -let arrayOfPoint: Point[]; +let point: Point = { x: 1, y: 2 }; +let point3d: Point3D = { x: 1, y: 2, z: 3 }; +let point3dOrUndef: Point3D | undefined; +let pointOrUndef: Point | undefined; +let arrayOfPoint: Point[] = []; let arrayOfPoint3D: Point3D[]; let arrayOfSymbol: symbol[]; let arrayOfPropertyKey: PropertyKey[]; let arrayOfAny: any[]; let arrayOfStringAny: [string, any][]; -let arrayLikeOfAny: ArrayLike; -let iterableOfPoint: IterableShim; -let iterableOfStringPoint: IterableShim<[string, Point]>; -let iterableOfPointPoint3D: IterableShim<[Point, Point3D]>; +let arrayLikeOfAny: ArrayLike = []; +let iterableOfPoint: IterableShim = []; +let iterableOfStringPoint: IterableShim<[string, Point]> = []; +let iterableOfPointPoint3D: IterableShim<[Point, Point3D]> = []; let iterableIteratorOfPoint: IterableIteratorShim; let iterableIteratorOfNumberPoint: IterableIteratorShim<[number, Point]>; let iterableIteratorOfNumber: IterableIteratorShim; @@ -37,16 +39,16 @@ let iterableIteratorOfAny: IterableIteratorShim; let iterableIteratorOfPropertyKey: IterableIteratorShim; let iterableIteratorOfPropertyKeyPoint: IterableIteratorShim<[PropertyKey, Point]>; let nodeList: NodeList; -let pd: PropertyDescriptor; -let pdm: PropertyDescriptorMap; -let map: Map; -let set: Set; -let weakMap: WeakMap; -let weakSet: WeakSet; -let promiseLikeOfPoint: PromiseLike; -let promiseLikeOfPoint3D: PromiseLike; -let promiseOfPoint: Promise; -let promiseOfPoint3D: Promise; +let pd: PropertyDescriptor = {}; +let pdm: PropertyDescriptorMap = {}; +let map: Map = new Map(); +let set: Set = new Set(); +let weakMap: WeakMap = new WeakMap(); +let weakSet: WeakSet = new WeakSet(); +let promiseLikeOfPoint: PromiseLike = Promise.resolve(point); +let promiseLikeOfPoint3D: PromiseLike = Promise.resolve(point3d); +let promiseOfPoint: Promise = Promise.resolve(point); +let promiseOfPoint3D: Promise = Promise.resolve(point); let promiseOfArrayOfPoint: Promise; let promiseOfVoid: Promise; @@ -102,7 +104,7 @@ i = Math.cbrt(i); map.clear(); map.delete(s); map.forEach((value: Point, key: string) => { }); -point = map.get(s); +pointOrUndef = map.get(s); b = map.has(s); map = map.set(s, point); i = map.size; @@ -117,7 +119,7 @@ i = set.size; set = new Set(); set = new Set(iterableOfPoint); weakMap.delete(point); -point3d = weakMap.get(point); +point3dOrUndef = weakMap.get(point); b = weakMap.has(point); weakMap = weakMap.set(point, point3d); weakMap = new WeakMap(); diff --git a/types/es6-shim/index.d.ts b/types/es6-shim/index.d.ts index 179313246f..9543bf770c 100644 --- a/types/es6-shim/index.d.ts +++ b/types/es6-shim/index.d.ts @@ -556,7 +556,7 @@ interface Map { clear(): void; delete(key: K): boolean; forEach(callbackfn: (value: V, index: K, map: Map) => void, thisArg?: any): void; - get(key: K): V; + get(key: K): V | undefined; has(key: K): boolean; set(key: K, value?: V): Map; size: number; @@ -596,7 +596,7 @@ declare var Set: SetConstructor; interface WeakMap { delete(key: K): boolean; - get(key: K): V; + get(key: K): V | undefined; has(key: K): boolean; set(key: K, value?: V): WeakMap; } diff --git a/types/es6-shim/tsconfig.json b/types/es6-shim/tsconfig.json index 1243a36ddb..02c35aee5a 100644 --- a/types/es6-shim/tsconfig.json +++ b/types/es6-shim/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -20,4 +20,4 @@ "index.d.ts", "es6-shim-tests.ts" ] -} \ No newline at end of file +} From d063f5275781a5a0eb35080065edec961e233a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Fri, 21 Apr 2017 20:05:25 +0200 Subject: [PATCH 4/9] =?UTF-8?q?Several=20fixes=20in=20tests,=20find(?= =?UTF-8?q?=E2=80=A6)=20may=20return=20`undefined`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `Array.find()` may return `undefined` according to MDN - `Array.findIndex()` may *not* return undefined in contrast to the JSDoc -> fixed JSDoc - installed es6-shim ^0.34 (not newest as `Reflect.enumerate()` is removed since es6-shim 0.35) - include yarn.lock in Git for es6-shim - import es6-shim module for running tests using CommonJS syntax - --- types/es6-shim/.gitignore | 1 + types/es6-shim/es6-shim-tests.ts | 26 ++++++++++++++++++-------- types/es6-shim/index.d.ts | 5 ++--- types/es6-shim/package.json | 5 +++++ types/es6-shim/yarn.lock | 7 +++++++ 5 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 types/es6-shim/.gitignore create mode 100644 types/es6-shim/package.json create mode 100644 types/es6-shim/yarn.lock diff --git a/types/es6-shim/.gitignore b/types/es6-shim/.gitignore new file mode 100644 index 0000000000..a59389a0ad --- /dev/null +++ b/types/es6-shim/.gitignore @@ -0,0 +1 @@ +!yarn.lock diff --git a/types/es6-shim/es6-shim-tests.ts b/types/es6-shim/es6-shim-tests.ts index 60a0e9fb4b..8f187e4d2b 100644 --- a/types/es6-shim/es6-shim-tests.ts +++ b/types/es6-shim/es6-shim-tests.ts @@ -1,11 +1,15 @@ -import './index' +declare const require: (module: string) => Object; +if (require !== null) { + require('es6-shim'); +} interface Point { x: number; y: number; } interface Point3D extends Point { z: number; } let a: any; let s: string = ''; -let i: number; +let i: number = 2; +let iOrUndef: number | undefined; let b: boolean; let f: () => void = () => {}; let o: Object; @@ -54,8 +58,8 @@ let promiseOfVoid: Promise; point = Object.assign(point, point); b = Object.is(point, point); -Object.setPrototypeOf(point, point); -point = arrayOfPoint.find(p => b); +Object.setPrototypeOf(point, {}); +pointOrUndef = arrayOfPoint.find(p => b); i = arrayOfPoint.findIndex(p => b); arrayOfPoint = arrayOfPoint.fill(point, i, arrayOfPoint.length); arrayOfPoint = arrayOfPoint.copyWithin(i, i, i); @@ -71,7 +75,7 @@ b = s.includes(s, i); b = s.endsWith(s, i); s = s.repeat(i); b = s.startsWith(s, i); -s = String.fromCodePoint(i, i); +s = String.fromCodePoint(2 as number, 3 as number); s = String.raw`abc`; s = r.flags; i = Number.EPSILON; @@ -186,6 +190,8 @@ promiseOfPoint = new Promise((resolve, reject) => resolve(point)); promiseOfPoint = new Promise((resolve, reject) => resolve(promiseOfPoint)); promiseOfPoint = new Promise((resolve, reject) => resolve(promiseLikeOfPoint)); promiseOfPoint = new Promise((resolve, reject) => reject(e)); +// To prevent UnhandledPromiseRejectionWarning +promiseOfPoint.catch(() => {}); promiseOfArrayOfPoint = Promise.all(arrayOfPoint); promiseOfArrayOfPoint = Promise.all(iterableOfPoint); promiseOfPoint = Promise.race(arrayOfPoint); @@ -195,7 +201,11 @@ promiseOfPoint = Promise.resolve(point3d); promiseOfPoint = Promise.resolve(promiseOfPoint); promiseOfPoint = Promise.resolve(promiseLikeOfPoint); promiseOfVoid = Promise.reject(e); +// To prevent UnhandledPromiseRejectionWarning +promiseOfVoid.catch(() => {}); promiseOfPoint = Promise.reject(e); +// To prevent UnhandledPromiseRejectionWarning +promiseOfPoint.catch(() => {}); a = Reflect.apply(f, a, arrayLikeOfAny); a = Reflect.construct(f, arrayLikeOfAny); b = Reflect.defineProperty(a, s, pd); @@ -205,9 +215,9 @@ b = Reflect.deleteProperty(a, s); b = Reflect.deleteProperty(a, i); b = Reflect.deleteProperty(a, sym); iterableIteratorOfAny = Reflect.enumerate(a); -a = Reflect.get(a, s, a); -a = Reflect.get(a, i, a); -a = Reflect.get(a, sym, a); +Reflect.get(a, s, a); +Reflect.get(a, i, a); +Reflect.get(a, sym, a); pd = Reflect.getOwnPropertyDescriptor(a, s); pd = Reflect.getOwnPropertyDescriptor(a, i); pd = Reflect.getOwnPropertyDescriptor(a, sym); diff --git a/types/es6-shim/index.d.ts b/types/es6-shim/index.d.ts index 9543bf770c..f310cfc231 100644 --- a/types/es6-shim/index.d.ts +++ b/types/es6-shim/index.d.ts @@ -185,11 +185,10 @@ interface Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: T, index: number, obj: Array) => boolean, thisArg?: any): T; + find(predicate: (value: T, index: number, obj: Array) => boolean, thisArg?: any): T | undefined; /** - * Returns the index of the first element in the array where predicate is true, and undefined - * otherwise. + * Returns the index of the first element in the array where predicate is true, and -1 otherwise. * @param predicate find calls predicate once for each element of the array, in ascending * order, until it finds one where predicate returns true. If such an element is found, find * immediately returns that element value. Otherwise, find returns undefined. diff --git a/types/es6-shim/package.json b/types/es6-shim/package.json new file mode 100644 index 0000000000..f9a738c9e5 --- /dev/null +++ b/types/es6-shim/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "es6-shim": "0.34" + } +} diff --git a/types/es6-shim/yarn.lock b/types/es6-shim/yarn.lock new file mode 100644 index 0000000000..c45109041f --- /dev/null +++ b/types/es6-shim/yarn.lock @@ -0,0 +1,7 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +es6-shim@0.34: + version "0.34.4" + resolved "https://registry.yarnpkg.com/es6-shim/-/es6-shim-0.34.4.tgz#b2f34d85ea0fd577fb2a5016cb978d44c5049969" From 9c1fa58d90eb1d359d86525879366f148199109e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Fri, 21 Apr 2017 21:13:12 +0200 Subject: [PATCH 5/9] removed .gitignore --- types/es6-shim/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 types/es6-shim/.gitignore diff --git a/types/es6-shim/.gitignore b/types/es6-shim/.gitignore deleted file mode 100644 index a59389a0ad..0000000000 --- a/types/es6-shim/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!yarn.lock From 7428e541f8397a42b45dd52824b029862bb24e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Fri, 21 Apr 2017 21:15:02 +0200 Subject: [PATCH 6/9] removed yarn.lock --- types/es6-shim/yarn.lock | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 types/es6-shim/yarn.lock diff --git a/types/es6-shim/yarn.lock b/types/es6-shim/yarn.lock deleted file mode 100644 index c45109041f..0000000000 --- a/types/es6-shim/yarn.lock +++ /dev/null @@ -1,7 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -es6-shim@0.34: - version "0.34.4" - resolved "https://registry.yarnpkg.com/es6-shim/-/es6-shim-0.34.4.tgz#b2f34d85ea0fd577fb2a5016cb978d44c5049969" From be1c9f19e17ebec1c59c27cc46a857dd982301d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Sat, 6 May 2017 11:19:33 +0200 Subject: [PATCH 7/9] Deleted package.json --- types/es6-shim/package.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 types/es6-shim/package.json diff --git a/types/es6-shim/package.json b/types/es6-shim/package.json deleted file mode 100644 index f9a738c9e5..0000000000 --- a/types/es6-shim/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "es6-shim": "0.34" - } -} From 6ea19e2aeaef01a587cf8983e5cb5255fceecea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Thu, 1 Jun 2017 20:52:32 +0200 Subject: [PATCH 8/9] =?UTF-8?q?Changed=20=E2=80=9CObject=E2=80=9D=20to=20?= =?UTF-8?q?=E2=80=9Cobject=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/es6-shim/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/es6-shim/index.d.ts b/types/es6-shim/index.d.ts index f310cfc231..99268a905e 100644 --- a/types/es6-shim/index.d.ts +++ b/types/es6-shim/index.d.ts @@ -593,7 +593,7 @@ interface SetConstructor { declare var Set: SetConstructor; -interface WeakMap { +interface WeakMap { delete(key: K): boolean; get(key: K): V | undefined; has(key: K): boolean; @@ -601,8 +601,8 @@ interface WeakMap { } interface WeakMapConstructor { - new (): WeakMap; - new (iterable: IterableShim<[K, V]>): WeakMap; + new (): WeakMap; + new (iterable: IterableShim<[K, V]>): WeakMap; prototype: WeakMap; } From 4258fbff7c9fc47d4052b0590933e4052cdadd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Thu, 1 Jun 2017 21:31:05 +0200 Subject: [PATCH 9/9] removed optionality of second parameter to (weak)map.set --- types/es6-shim/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/es6-shim/index.d.ts b/types/es6-shim/index.d.ts index 99268a905e..4c03fc8b9e 100644 --- a/types/es6-shim/index.d.ts +++ b/types/es6-shim/index.d.ts @@ -557,7 +557,7 @@ interface Map { forEach(callbackfn: (value: V, index: K, map: Map) => void, thisArg?: any): void; get(key: K): V | undefined; has(key: K): boolean; - set(key: K, value?: V): Map; + set(key: K, value: V): Map; size: number; entries(): IterableIteratorShim<[K, V]>; keys(): IterableIteratorShim; @@ -597,7 +597,7 @@ interface WeakMap { delete(key: K): boolean; get(key: K): V | undefined; has(key: K): boolean; - set(key: K, value?: V): WeakMap; + set(key: K, value: V): WeakMap; } interface WeakMapConstructor {