From 2e13ca4b697f5201b6cba5fd3e77a8e828f62202 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Fri, 7 Feb 2020 23:05:28 +0100 Subject: [PATCH] =?UTF-8?q?feat(object.getownpropertydescriptors):=20Add?= =?UTF-8?q?=C2=A0missing=C2=A0files=20(#42188)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../implementation.d.ts | 13 +++++ .../index.d.ts | 24 ++++++--- .../object.getownpropertydescriptors-tests.ts | 53 ++++++++++++------- .../polyfill.d.ts | 4 ++ .../shim.d.ts | 4 ++ .../tsconfig.json | 38 ++++++------- 6 files changed, 88 insertions(+), 48 deletions(-) create mode 100644 types/object.getownpropertydescriptors/implementation.d.ts create mode 100644 types/object.getownpropertydescriptors/polyfill.d.ts create mode 100644 types/object.getownpropertydescriptors/shim.d.ts diff --git a/types/object.getownpropertydescriptors/implementation.d.ts b/types/object.getownpropertydescriptors/implementation.d.ts new file mode 100644 index 0000000000..25e7e6973e --- /dev/null +++ b/types/object.getownpropertydescriptors/implementation.d.ts @@ -0,0 +1,13 @@ +/** + * Returns an object containing all own property descriptors of an object + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ +declare function polyfill( + o: T, +): { + -readonly [P in keyof T]: TypedPropertyDescriptor; +} & { + [property: string]: PropertyDescriptor; +}; + +export = polyfill; diff --git a/types/object.getownpropertydescriptors/index.d.ts b/types/object.getownpropertydescriptors/index.d.ts index 1bac152dd6..7eb566ca53 100644 --- a/types/object.getownpropertydescriptors/index.d.ts +++ b/types/object.getownpropertydescriptors/index.d.ts @@ -1,20 +1,30 @@ -// Type definitions for object.getownpropertydescriptors 2.0 +// Type definitions for object.getownpropertydescriptors 2.1 // Project: https://github.com/ljharb/object.getownpropertydescriptors#readme // Definitions by: Vitor Luiz Cavalcanti // Jordan Harband +// ExE Boss // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 + +import polyfill = require('./implementation'); +import getImpl = require('./polyfill'); +import shimImpl = require('./shim'); /** * Returns an object containing all own property descriptors of an object - * @param o - Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ -declare function getOwnPropertyDescriptors (o: T): { [K in keyof T]: TypedPropertyDescriptor } & PropertyDescriptorMap; +declare function getOwnPropertyDescriptors( + o: T, +): { + -readonly [P in keyof T]: TypedPropertyDescriptor; +} & { + [property: string]: PropertyDescriptor; +}; declare namespace getOwnPropertyDescriptors { - function shim(): typeof getOwnPropertyDescriptors; - function getPolyfill(): typeof getOwnPropertyDescriptors; - function implementation(): typeof getOwnPropertyDescriptors; + function getPolyfill(): ReturnType; + const implementation: typeof polyfill; + function shim(): ReturnType; } export = getOwnPropertyDescriptors; diff --git a/types/object.getownpropertydescriptors/object.getownpropertydescriptors-tests.ts b/types/object.getownpropertydescriptors/object.getownpropertydescriptors-tests.ts index 3212a87af1..199ce2abdc 100644 --- a/types/object.getownpropertydescriptors/object.getownpropertydescriptors-tests.ts +++ b/types/object.getownpropertydescriptors/object.getownpropertydescriptors-tests.ts @@ -1,27 +1,40 @@ -import descriptors = require('object.getownpropertydescriptors'); +import getOwnPropertyDescriptors = require('object.getownpropertydescriptors'); -descriptors({ language: 'TypeScript' }); -// => { language: TypedPropertyDescriptor; } +/** + * The `expectType` function from https://www.npmjs.com/package/tsd, + * except instead of returning `void`, it returns `T`. + */ +declare function expectType(value: T): T; -const { language } = descriptors({ language: 'TypeScript' }); +interface Language { + language: string; + description?: string; +} -language; -// => { -// writable: undefined | boolean, -// enumerable: undefined | boolean, -// configurable: undefined | boolean, -// get: undefined | (() => string), -// set: undefined | ((value: string) => void), -// value: undefined | string -// } +interface LanguageDescriptorMap { + language: TypedPropertyDescriptor; + description?: TypedPropertyDescriptor; +} -descriptors.shim(); -// => typeof descriptors +declare let lang: Language; -const getOwnPropertyDescriptorsPolyfill = descriptors.getPolyfill(); +// $ExpectType LanguageDescriptorMap & PropertyDescriptorMap +const langDesc = expectType(getOwnPropertyDescriptors(lang)); -getOwnPropertyDescriptorsPolyfill({ name: 'object.getownpropertydescriptors' }); -// => { name: TypedPropertyDescriptor; } +langDesc.language; // $ExpectType TypedPropertyDescriptor +langDesc.description; // $ExpectType TypedPropertyDescriptor | undefined +langDesc.foo; // $ExpectType PropertyDescriptor -descriptors.implementation(); -// => typeof descriptors +// $ExpectType (o: T) => { -readonly [P in keyof T]: TypedPropertyDescriptor; } & { [property: string]: PropertyDescriptor; } +let implementation = getOwnPropertyDescriptors.getPolyfill(); +implementation = getOwnPropertyDescriptors.shim(); +implementation = getOwnPropertyDescriptors.implementation; + +import polyfillImpl = require('object.getownpropertydescriptors/implementation'); +implementation = polyfillImpl; + +import getPolyfill = require('object.getownpropertydescriptors/polyfill'); +implementation = getPolyfill(); + +import shimGetOwnPropertyDescriptors = require('object.getownpropertydescriptors/shim'); +implementation = shimGetOwnPropertyDescriptors(); diff --git a/types/object.getownpropertydescriptors/polyfill.d.ts b/types/object.getownpropertydescriptors/polyfill.d.ts new file mode 100644 index 0000000000..428fe44cf6 --- /dev/null +++ b/types/object.getownpropertydescriptors/polyfill.d.ts @@ -0,0 +1,4 @@ +import getOwnPropertyDescriptors = require('./implementation'); + +declare function getPolyfill(): typeof getOwnPropertyDescriptors; +export = getPolyfill; diff --git a/types/object.getownpropertydescriptors/shim.d.ts b/types/object.getownpropertydescriptors/shim.d.ts new file mode 100644 index 0000000000..d3ec1f46a4 --- /dev/null +++ b/types/object.getownpropertydescriptors/shim.d.ts @@ -0,0 +1,4 @@ +import getPolyfill = require('./polyfill'); + +declare function shimGetOwnPropertyDescriptors(): ReturnType; +export = shimGetOwnPropertyDescriptors; diff --git a/types/object.getownpropertydescriptors/tsconfig.json b/types/object.getownpropertydescriptors/tsconfig.json index 4afa48dce3..08c592030d 100644 --- a/types/object.getownpropertydescriptors/tsconfig.json +++ b/types/object.getownpropertydescriptors/tsconfig.json @@ -1,23 +1,19 @@ { - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "object.getownpropertydescriptors-tests.ts" - ] + "compilerOptions": { + "module": "commonjs", + "lib": ["es2015"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "object.getownpropertydescriptors-tests.ts", + "index.d.ts" + ] }