mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
feat(object.getownpropertydescriptors): Add missing files (#42188)
This commit is contained in:
@@ -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<T>(
|
||||
o: T,
|
||||
): {
|
||||
-readonly [P in keyof T]: TypedPropertyDescriptor<T[P]>;
|
||||
} & {
|
||||
[property: string]: PropertyDescriptor;
|
||||
};
|
||||
|
||||
export = polyfill;
|
||||
+17
-7
@@ -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 <https://github.com/VitorLuizC>
|
||||
// Jordan Harband <https://github.com/ljharb>
|
||||
// ExE Boss <https://github.com/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 <T extends object>(o: T): { [K in keyof T]: TypedPropertyDescriptor<T[K]> } & PropertyDescriptorMap;
|
||||
declare function getOwnPropertyDescriptors<T>(
|
||||
o: T,
|
||||
): {
|
||||
-readonly [P in keyof T]: TypedPropertyDescriptor<T[P]>;
|
||||
} & {
|
||||
[property: string]: PropertyDescriptor;
|
||||
};
|
||||
|
||||
declare namespace getOwnPropertyDescriptors {
|
||||
function shim(): typeof getOwnPropertyDescriptors;
|
||||
function getPolyfill(): typeof getOwnPropertyDescriptors;
|
||||
function implementation(): typeof getOwnPropertyDescriptors;
|
||||
function getPolyfill(): ReturnType<typeof getImpl>;
|
||||
const implementation: typeof polyfill;
|
||||
function shim(): ReturnType<typeof shimImpl>;
|
||||
}
|
||||
|
||||
export = getOwnPropertyDescriptors;
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
import descriptors = require('object.getownpropertydescriptors');
|
||||
import getOwnPropertyDescriptors = require('object.getownpropertydescriptors');
|
||||
|
||||
descriptors({ language: 'TypeScript' });
|
||||
// => { language: TypedPropertyDescriptor<string>; }
|
||||
/**
|
||||
* The `expectType` function from https://www.npmjs.com/package/tsd,
|
||||
* except instead of returning `void`, it returns `T`.
|
||||
*/
|
||||
declare function expectType<T>(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<string>;
|
||||
description?: TypedPropertyDescriptor<string | undefined>;
|
||||
}
|
||||
|
||||
descriptors.shim();
|
||||
// => typeof descriptors
|
||||
declare let lang: Language;
|
||||
|
||||
const getOwnPropertyDescriptorsPolyfill = descriptors.getPolyfill();
|
||||
// $ExpectType LanguageDescriptorMap & PropertyDescriptorMap
|
||||
const langDesc = expectType<LanguageDescriptorMap & PropertyDescriptorMap>(getOwnPropertyDescriptors(lang));
|
||||
|
||||
getOwnPropertyDescriptorsPolyfill({ name: 'object.getownpropertydescriptors' });
|
||||
// => { name: TypedPropertyDescriptor<string>; }
|
||||
langDesc.language; // $ExpectType TypedPropertyDescriptor<string>
|
||||
langDesc.description; // $ExpectType TypedPropertyDescriptor<string | undefined> | undefined
|
||||
langDesc.foo; // $ExpectType PropertyDescriptor
|
||||
|
||||
descriptors.implementation();
|
||||
// => typeof descriptors
|
||||
// $ExpectType <T>(o: T) => { -readonly [P in keyof T]: TypedPropertyDescriptor<T[P]>; } & { [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();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import getOwnPropertyDescriptors = require('./implementation');
|
||||
|
||||
declare function getPolyfill(): typeof getOwnPropertyDescriptors;
|
||||
export = getPolyfill;
|
||||
@@ -0,0 +1,4 @@
|
||||
import getPolyfill = require('./polyfill');
|
||||
|
||||
declare function shimGetOwnPropertyDescriptors(): ReturnType<typeof getPolyfill>;
|
||||
export = shimGetOwnPropertyDescriptors;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user