From 21abd0b325000a3bf25286fb9c9f00f49bf79f1b Mon Sep 17 00:00:00 2001 From: paull39 Date: Mon, 21 Sep 2020 17:33:14 +0200 Subject: [PATCH] preact-custom-elements types (#47779) * preact-custom-elements types * Tabs to Spaces * test case for function call register from package preact-custom-element * typing to export equals convention * Tests adjusted to naming convention * commonjs syntax for backwards compatibility Co-authored-by: Kasper --- types/preact-custom-element/index.d.ts | 15 +++++++++++ types/preact-custom-element/package.json | 6 +++++ .../preact-custom-element-tests.tsx | 8 ++++++ types/preact-custom-element/tsconfig.json | 27 +++++++++++++++++++ types/preact-custom-element/tslint.json | 3 +++ 5 files changed, 59 insertions(+) create mode 100644 types/preact-custom-element/index.d.ts create mode 100644 types/preact-custom-element/package.json create mode 100644 types/preact-custom-element/preact-custom-element-tests.tsx create mode 100644 types/preact-custom-element/tsconfig.json create mode 100644 types/preact-custom-element/tslint.json diff --git a/types/preact-custom-element/index.d.ts b/types/preact-custom-element/index.d.ts new file mode 100644 index 0000000000..90b10814f2 --- /dev/null +++ b/types/preact-custom-element/index.d.ts @@ -0,0 +1,15 @@ +// Type definitions for preact-custom-element 4.0 +// Project: https://github.com/preactjs/preact-custom-element#readme +// Definitions by: Nicolai Kasper +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.9 + +import { ComponentClass, FunctionComponent, FunctionalComponent } from 'preact'; +declare function register( + componentDefinition: FunctionComponent | ComponentClass | FunctionalComponent, + tagName: string, + observedAttributes?: string[], + options?: { shadow: boolean }, +): void; + +export = register; diff --git a/types/preact-custom-element/package.json b/types/preact-custom-element/package.json new file mode 100644 index 0000000000..161a5cbf60 --- /dev/null +++ b/types/preact-custom-element/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "preact": "^10.0.0" + } +} diff --git a/types/preact-custom-element/preact-custom-element-tests.tsx b/types/preact-custom-element/preact-custom-element-tests.tsx new file mode 100644 index 0000000000..a838ed1ed6 --- /dev/null +++ b/types/preact-custom-element/preact-custom-element-tests.tsx @@ -0,0 +1,8 @@ +import { h, render, Component, FunctionalComponent } from 'preact'; +import register = require('preact-custom-element'); + +const Foo: FunctionalComponent = props => { + return
; +}; + +register(Foo, 'my-foo'); diff --git a/types/preact-custom-element/tsconfig.json b/types/preact-custom-element/tsconfig.json new file mode 100644 index 0000000000..d19cd7a0c4 --- /dev/null +++ b/types/preact-custom-element/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "jsx": "react", + "jsxFactory": "h", + "experimentalDecorators": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "preact-custom-element-tests.tsx" + ] +} diff --git a/types/preact-custom-element/tslint.json b/types/preact-custom-element/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/preact-custom-element/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}