diff --git a/types/define-properties/.editorconfig b/types/define-properties/.editorconfig new file mode 100644 index 0000000000..a0207fa43b --- /dev/null +++ b/types/define-properties/.editorconfig @@ -0,0 +1,3 @@ +# This package uses tabs +[*] +indent_style = tab diff --git a/types/define-properties/define-properties-tests.ts b/types/define-properties/define-properties-tests.ts new file mode 100644 index 0000000000..225aead97d --- /dev/null +++ b/types/define-properties/define-properties-tests.ts @@ -0,0 +1,47 @@ +import define = require('define-properties'); + +declare function __classPrivateFieldGet(receiver: T, privateMap: WeakMap): V; + +const object: object = undefined!; +const object_foo = new WeakMap(); + +// $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', +}); diff --git a/types/define-properties/index.d.ts b/types/define-properties/index.d.ts new file mode 100644 index 0000000000..563d0f5be6 --- /dev/null +++ b/types/define-properties/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for define-properties 1.1 +// Project: https://github.com/ljharb/define-properties#readme +// Definitions by: 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( + object: object, + map: Record & ThisType, + predicates?: Partial boolean>>, +): void; +export = defineProperties; diff --git a/types/define-properties/tsconfig.json b/types/define-properties/tsconfig.json new file mode 100644 index 0000000000..62880484aa --- /dev/null +++ b/types/define-properties/tsconfig.json @@ -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"] +} diff --git a/types/define-properties/tslint.json b/types/define-properties/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/define-properties/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }