mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
chore: Update and fix config type test
This commit is contained in:
25
lib/config/builder/config-types.test.ts
Normal file
25
lib/config/builder/config-types.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
ListValueSpecOf,
|
||||
ValueSpecList,
|
||||
isValueSpecListOf,
|
||||
} from "../config-types";
|
||||
import { Config } from "./config";
|
||||
import { List } from "./list";
|
||||
import { Value } from "./value";
|
||||
|
||||
describe("Config Types", () => {
|
||||
test("isValueSpecListOf", () => {
|
||||
const options = [List.obj, List.string, List.number];
|
||||
for (const option of options) {
|
||||
const test = option({} as any, { spec: Config.of({}) } as any) as any;
|
||||
const someList = Value.list(test).build();
|
||||
if (isValueSpecListOf(someList, "string")) {
|
||||
someList.spec satisfies ListValueSpecOf<"string">;
|
||||
} else if (isValueSpecListOf(someList, "number")) {
|
||||
someList.spec satisfies ListValueSpecOf<"number">;
|
||||
} else if (isValueSpecListOf(someList, "object")) {
|
||||
someList.spec satisfies ListValueSpecOf<"object">;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -129,9 +129,9 @@ export interface ValueSpecListOf<T extends ListValueSpecType>
|
||||
|
||||
// sometimes the type checker needs just a little bit of help
|
||||
export function isValueSpecListOf<S extends ListValueSpecType>(
|
||||
t: ValueSpecList,
|
||||
t: ValueSpecListOf<ListValueSpecType>,
|
||||
s: S
|
||||
): t is ValueSpecListOf<S> {
|
||||
): t is ValueSpecListOf<S> & { spec: ListValueSpecOf<S> } {
|
||||
return t.spec.type === s;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user