From 76105d9466fe23d8a3742b9b3fa8548cf6381f0c Mon Sep 17 00:00:00 2001 From: Alexander Azarov Date: Tue, 5 Sep 2017 23:05:53 +0300 Subject: [PATCH 1/2] 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 + } +} From 6b4042f6cd6e09e5f1f5c991b5b7b22e802ea337 Mon Sep 17 00:00:00 2001 From: Alexander Azarov Date: Thu, 7 Sep 2017 21:22:28 +0300 Subject: [PATCH 2/2] Module function template used per @sandersn request --- types/picturefill/index.d.ts | 5 ++--- types/picturefill/tslint.json | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/types/picturefill/index.d.ts b/types/picturefill/index.d.ts index f41e46a3d7..3c12117841 100644 --- a/types/picturefill/index.d.ts +++ b/types/picturefill/index.d.ts @@ -14,6 +14,5 @@ declare namespace Picturefill { declare function picturefill(arg?: Picturefill.EvaluateArg): void; -declare module 'picturefill' { - export = picturefill; -} +export = picturefill; +export as namespace picturefill; diff --git a/types/picturefill/tslint.json b/types/picturefill/tslint.json index e765bc9e16..d88586e5bd 100644 --- a/types/picturefill/tslint.json +++ b/types/picturefill/tslint.json @@ -1,6 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "no-single-declare-module": false - } + "extends": "dtslint/dt.json" }