mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat: Add define‑properties (#39058)
* feat: Add `define‑properties` * fix(define‑properties): Correct definition authors
This commit is contained in:
parent
192a1b5b5b
commit
9294a66f12
3
types/define-properties/.editorconfig
Normal file
3
types/define-properties/.editorconfig
Normal file
@ -0,0 +1,3 @@
|
||||
# This package uses tabs
|
||||
[*]
|
||||
indent_style = tab
|
||||
47
types/define-properties/define-properties-tests.ts
Normal file
47
types/define-properties/define-properties-tests.ts
Normal 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
27
types/define-properties/index.d.ts
vendored
Normal 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;
|
||||
16
types/define-properties/tsconfig.json
Normal file
16
types/define-properties/tsconfig.json
Normal 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"]
|
||||
}
|
||||
1
types/define-properties/tslint.json
Normal file
1
types/define-properties/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user