@thednp/shorty 2.0.0-alpha20 → 2.0.0-alpha21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thednp/shorty",
3
- "version": "2.0.0alpha20",
3
+ "version": "2.0.0alpha21",
4
4
  "description": "TypeScript shorties for the web",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/shorty.js",
@@ -13,11 +13,11 @@ import ObjectAssign from './ObjectAssign';
13
13
  * @param param `tagName` or object
14
14
  * @return a new `HTMLElement`
15
15
  */
16
- const createElement = (param?: string | Partial<HTMLElement>): HTMLElement | undefined => {
16
+ const createElement = <T extends HTMLElement>(param?: string | Partial<T>): T | undefined => {
17
17
  if (!param) return undefined;
18
18
 
19
19
  if (isString(param)) {
20
- return getDocument().createElement(param);
20
+ return getDocument().createElement(param) as T;
21
21
  }
22
22
 
23
23
  const { tagName } = param;
@@ -28,7 +28,7 @@ const createElement = (param?: string | Partial<HTMLElement>): HTMLElement | und
28
28
  const attr = { ...(param as Record<string, unknown>) };
29
29
  delete attr.tagName;
30
30
 
31
- return ObjectAssign(newElement, attr);
31
+ return ObjectAssign(newElement, attr) as unknown as T;
32
32
  };
33
33
 
34
34
  export default createElement;
@@ -16,14 +16,14 @@ import isString from '../is/isString';
16
16
  * @param param `tagName` or object
17
17
  * @return a new `HTMLElement`
18
18
  */
19
- const createElementNS = (
19
+ const createElementNS = <T extends HTMLElement>(
20
20
  ns: string,
21
- param?: string | Partial<HTMLElement>,
22
- ): HTMLElement | undefined => {
21
+ param?: string | Partial<T>,
22
+ ): T | undefined => {
23
23
  if (!ns || !param) return undefined;
24
24
 
25
25
  if (isString(param)) {
26
- return getDocument().createElementNS(ns, param) as HTMLElement;
26
+ return getDocument().createElementNS(ns, param) as T;
27
27
  }
28
28
 
29
29
  const { tagName } = param;
@@ -34,7 +34,7 @@ const createElementNS = (
34
34
  const attr = { ...(param as Record<string, unknown>) };
35
35
  delete attr.tagName;
36
36
 
37
- return ObjectAssign(newElement, attr);
37
+ return ObjectAssign(newElement, attr) as unknown as T;
38
38
  };
39
39
 
40
40
  export default createElementNS;