Skip to content

Commit be194cb

Browse files
committed
ref: extract types to own file
1 parent 1616501 commit be194cb

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from "./math";
55
export * from "./misc";
66
export * from "./SelectorObserver";
77
export * from "./translation";
8+
export * from "./types";

lib/misc.ts

+1-32
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
import { getUnsafeWindow } from "./dom";
2-
3-
/** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */
4-
export type Stringifiable = string | { toString(): string };
5-
6-
/**
7-
* A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.
8-
* Supports unions of strings, numbers and objects.
9-
*/
10-
export type LooseUnion<TUnion extends string | number | object> =
11-
(TUnion) | (
12-
TUnion extends string
13-
? (string & {})
14-
: (
15-
TUnion extends number
16-
? (number & {})
17-
: (
18-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19-
TUnion extends Record<keyof any, unknown>
20-
? (object & {})
21-
: never
22-
)
23-
)
24-
);
25-
26-
/**
27-
* A type that allows all strings except for empty ones
28-
* @example
29-
* function foo<T extends string>(bar: NonEmptyString<T>) {
30-
* console.log(bar);
31-
* }
32-
*/
33-
export type NonEmptyString<TString extends string> = TString extends "" ? never : TString;
2+
import type { Stringifiable } from "./types";
343

354
/**
365
* Automatically appends an `s` to the passed {@linkcode word}, if {@linkcode num} is not equal to 1

lib/translation.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Stringifiable, insertValues } from "./misc";
1+
import { insertValues } from "./misc";
2+
import type { Stringifiable } from "./types";
23

34
/** Trans rights! 🏳️‍⚧️ */
45
const trans: Record<string, Record<string, string>> = {};

lib/types.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */
2+
export type Stringifiable = string | { toString(): string };
3+
4+
/**
5+
* A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.
6+
* Supports unions of strings, numbers and objects.
7+
*/
8+
export type LooseUnion<TUnion extends string | number | object> =
9+
(TUnion) | (
10+
TUnion extends string
11+
? (string & {})
12+
: (
13+
TUnion extends number
14+
? (number & {})
15+
: (
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17+
TUnion extends Record<keyof any, unknown>
18+
? (object & {})
19+
: never
20+
)
21+
)
22+
);
23+
24+
/**
25+
* A type that allows all strings except for empty ones
26+
* @example
27+
* function foo<T extends string>(bar: NonEmptyString<T>) {
28+
* console.log(bar);
29+
* }
30+
*/
31+
export type NonEmptyString<TString extends string> = TString extends "" ? never : TString;

0 commit comments

Comments
 (0)