From 76105d9466fe23d8a3742b9b3fa8548cf6381f0c Mon Sep 17 00:00:00 2001 From: Alexander Azarov Date: Tue, 5 Sep 2017 23:05:53 +0300 Subject: [PATCH] Type definitions for `picturefill` It's a module function, so should be imported like ``` import picturefill = require('picturefill'); ``` --- types/picturefill/index.d.ts | 19 +++++++++++++++++++ types/picturefill/picturefill-tests.ts | 17 +++++++++++++++++ types/picturefill/tsconfig.json | 23 +++++++++++++++++++++++ types/picturefill/tslint.json | 6 ++++++ 4 files changed, 65 insertions(+) create mode 100644 types/picturefill/index.d.ts create mode 100644 types/picturefill/picturefill-tests.ts create mode 100644 types/picturefill/tsconfig.json create mode 100644 types/picturefill/tslint.json diff --git a/types/picturefill/index.d.ts b/types/picturefill/index.d.ts new file mode 100644 index 0000000000..f41e46a3d7 --- /dev/null +++ b/types/picturefill/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for picturefill 3.0 +// Project: https://scottjehl.github.io/picturefill/ +// Definitions by: Alexander Azarov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace Picturefill { + type ElementNullable = Element | null; + + interface EvaluateArg { + reevaluate?: boolean; + elements: NodeList | ElementNullable[]; + } +} + +declare function picturefill(arg?: Picturefill.EvaluateArg): void; + +declare module 'picturefill' { + export = picturefill; +} diff --git a/types/picturefill/picturefill-tests.ts b/types/picturefill/picturefill-tests.ts new file mode 100644 index 0000000000..306a3f6ded --- /dev/null +++ b/types/picturefill/picturefill-tests.ts @@ -0,0 +1,17 @@ +function test_elements() { + // no args + picturefill(); + + // Element[] + picturefill({elements: [ document.getElementById('#id') ]}); + + // NodeList + picturefill({elements: document.querySelectorAll('img')}); +} + +function test_optional() { + picturefill({ + elements: [], + reevaluate: true + }); +} diff --git a/types/picturefill/tsconfig.json b/types/picturefill/tsconfig.json new file mode 100644 index 0000000000..0fefbd709d --- /dev/null +++ b/types/picturefill/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "picturefill-tests.ts" + ] +} diff --git a/types/picturefill/tslint.json b/types/picturefill/tslint.json new file mode 100644 index 0000000000..e765bc9e16 --- /dev/null +++ b/types/picturefill/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-single-declare-module": false + } +}