feat: Add define‑properties (#39058)

* feat: Add `define‑properties`

* fix(define‑properties): Correct definition authors
This commit is contained in:
ExE Boss 2019-10-16 23:06:55 +02:00 committed by Andrew Branch
parent 192a1b5b5b
commit 9294a66f12
5 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# This package uses tabs
[*]
indent_style = tab

View File

@ -0,0 +1,47 @@
import define = require('define-properties');
declare function __classPrivateFieldGet<T extends object, V>(receiver: T, privateMap: WeakMap<T, V>): V;
const object: object = undefined!;
const object_foo = new WeakMap<object, string>();
// $ExpectType boolean
define.supportsDescriptors;
// $ExpectType typeof defineProperties
define;
// $ExpectError
define(object);
// $ExpectError
define(null, {});
define(object, {
getFoo() {
this; // $ExpectType any
return __classPrivateFieldGet(this, object_foo);
}
});
define(object, {
foo: 'any'
}, {
foo: () => (object as any).foo !== 'any'
});
// $ExpectError
define(object, {
foo: 'any'
}, {
foo: () => (object as any).foo !== 'any',
bar: () => { throw new Error(); },
});
define(object, {
foo: 'any',
bar: 'valid'
}, {
foo: () => (object as any).foo !== 'any',
});

27
types/define-properties/index.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
// Type definitions for define-properties 1.1
// Project: https://github.com/ljharb/define-properties#readme
// Definitions by: ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
declare namespace defineProperties {
/**
* Whether the current environment correctly supports property descriptors.
*/
const supportsDescriptors: boolean;
}
/**
* Defines new properties in `map` as non-enumerable if they don't already
* exist on `object`.
*
* @param object The object to define non-enumerable properties on.
* @param map The map of newly defined properties.
* @param predicates The optional predicates map, return `true` to override existing properties on `object`.
*/
declare function defineProperties<K extends keyof any>(
object: object,
map: Record<K, any> & ThisType<any>,
predicates?: Partial<Record<K, () => boolean>>,
): void;
export = defineProperties;

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "define-properties-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }