Pārlūkot izejas kodu

ref: extract types to own file

Sv443 11 mēneši atpakaļ
vecāks
revīzija
be194cb46b
4 mainītis faili ar 35 papildinājumiem un 33 dzēšanām
  1. 1 0
      lib/index.ts
  2. 1 32
      lib/misc.ts
  3. 2 1
      lib/translation.ts
  4. 31 0
      lib/types.ts

+ 1 - 0
lib/index.ts

@@ -5,3 +5,4 @@ export * from "./math";
 export * from "./misc";
 export * from "./SelectorObserver";
 export * from "./translation";
+export * from "./types";

+ 1 - 32
lib/misc.ts

@@ -1,36 +1,5 @@
 import { getUnsafeWindow } from "./dom";
-
-/** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */
-export type Stringifiable = string | { toString(): string };
-
-/**
- * A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.  
- * Supports unions of strings, numbers and objects.
- */
-export type LooseUnion<TUnion extends string | number | object> =
-  (TUnion) | (
-    TUnion extends string
-      ? (string & {})
-      : (
-        TUnion extends number
-          ? (number & {})
-          : (
-            // eslint-disable-next-line @typescript-eslint/no-explicit-any
-            TUnion extends Record<keyof any, unknown>
-            ? (object & {})
-            : never
-          )
-      )
-  );
-
-/**
- * A type that allows all strings except for empty ones
- * @example
- * function foo<T extends string>(bar: NonEmptyString<T>) {
- *   console.log(bar);
- * }
- */
-export type NonEmptyString<TString extends string> = TString extends "" ? never : TString;
+import type { Stringifiable } from "./types";
 
 /**
  * Automatically appends an `s` to the passed {@linkcode word}, if {@linkcode num} is not equal to 1

+ 2 - 1
lib/translation.ts

@@ -1,4 +1,5 @@
-import { Stringifiable, insertValues } from "./misc";
+import { insertValues } from "./misc";
+import type { Stringifiable } from "./types";
 
 /** Trans rights! 🏳️‍⚧️ */
 const trans: Record<string, Record<string, string>> = {};

+ 31 - 0
lib/types.ts

@@ -0,0 +1,31 @@
+/** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */
+export type Stringifiable = string | { toString(): string };
+
+/**
+ * A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.  
+ * Supports unions of strings, numbers and objects.
+ */
+export type LooseUnion<TUnion extends string | number | object> =
+  (TUnion) | (
+    TUnion extends string
+      ? (string & {})
+      : (
+        TUnion extends number
+          ? (number & {})
+          : (
+            // eslint-disable-next-line @typescript-eslint/no-explicit-any
+            TUnion extends Record<keyof any, unknown>
+            ? (object & {})
+            : never
+          )
+      )
+  );
+
+/**
+ * A type that allows all strings except for empty ones
+ * @example
+ * function foo<T extends string>(bar: NonEmptyString<T>) {
+ *   console.log(bar);
+ * }
+ */
+export type NonEmptyString<TString extends string> = TString extends "" ? never : TString;