From 99f18ae5d19ff167b8391eabcdec18a46eb1cba2 Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 27 Mar 2021 18:22:36 -0500 Subject: [PATCH] feat(reflect): handle missing prototypes Typescript 4.2 fixed a return type for objects without a prototype. This change throws an InvalidValueError for these, rather than the TypeError that was previously thrown. --- .gitignore | 1 + package.json | 4 ++-- src/Reflect.ts | 8 +++++++- test/utils/TestReflect.ts | 9 +++++++++ yarn.lock | 21 +++++++++++++-------- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index f069d17..dae5c97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .awcache/ .licenses/ .nyc_output/ +.vscode/ node_modules/ out/ temp/ diff --git a/package.json b/package.json index d4e2dd0..6df8975 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@types/lodash": "4.14.168", "@types/mocha": "8.2.2", "@types/mock-fs": "4.13.0", - "@types/node": "14.14.25", + "@types/node": "14.14.37", "@types/sinon-chai": "3.2.5", "@types/source-map-support": "0.5.3", "@typescript-eslint/eslint-plugin": "4.19.0", @@ -73,7 +73,7 @@ "tslint-etc": "1.13.9", "tslint-microsoft-contrib": "6.2.0", "tslint-sonarts": "1.9.0", - "typescript": "4.1.3" + "typescript": "4.2.3" }, "nyc": { "extends": "@istanbuljs/nyc-config-typescript" diff --git a/src/Reflect.ts b/src/Reflect.ts index 8381077..ebb724e 100644 --- a/src/Reflect.ts +++ b/src/Reflect.ts @@ -1,3 +1,4 @@ +import { InvalidArgumentError } from './error/InvalidArgumentError'; import { doesExist, isNil } from './Maybe'; /* eslint-disable-next-line @typescript-eslint/ban-types */ @@ -50,5 +51,10 @@ export function getMethods(value: TValue): Set { const instance = new Test(); expect(constructorName(instance)).to.equal(Test.name); }); + + it('should throw when value has no prototype', () => { + /* eslint-disable-next-line no-null/no-null */ + const protoless = Object.create(null, {}); + expect(() => constructorName(protoless)).to.throw(InvalidArgumentError); + }); + + xit('should handle nil values'); }); }); diff --git a/yarn.lock b/yarn.lock index b9fe70e..9c4fca1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -423,10 +423,10 @@ resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/node/-/node-10.17.13.tgz#ccebcdb990bd6139cd16e84c39dc2fb1023ca90c" integrity sha512-pMCcqU2zT4TjqYFrWtYHKal7Sl30Ims6ulZ4UFXxI4xbtQqK/qqKwkDoBFCfooRqqmRu9vY3xaJRwxSh673aYg== -"@types/node@14.14.25": - version "14.14.25" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/node/-/node-14.14.25.tgz#15967a7b577ff81383f9b888aa6705d43fbbae93" - integrity sha512-EPpXLOVqDvisVxtlbvzfyqSsFeQxltFbluZNRndIb8tr9KiBnYNLzrc1N3pyKUCww2RNrfHDViqDWWE1LCJQtQ== +"@types/node@14.14.37": + version "14.14.37" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/node/-/node-14.14.37.tgz#a3dd8da4eb84a996c36e331df98d82abd76b516e" + integrity sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw== "@types/normalize-package-data@^2.4.0": version "2.4.0" @@ -4641,16 +4641,21 @@ typedarray@^0.0.6: resolved "https://artifacts.apextoaster.com/repository/group-npm/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@4.1.3, typescript@~4.1.3: - version "4.1.3" - resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" - integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== +typescript@4.2.3: + version "4.2.3" + resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3" + integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw== typescript@^3.0.0: version "3.6.3" resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da" integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw== +typescript@~4.1.3: + version "4.1.3" + resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" + integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== + uglify-js@^3.1.4: version "3.6.0" resolved "https://artifacts.apextoaster.com/repository/group-npm/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5"