This repository has been archived on 2026-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

38 lines
573 B
TypeScript

import * as t from "..";
test("functions act as generics", () => {
function genericStruct<T>(u: t.Type<T>) {
return t.subtype({
hi: t.str,
foo: u,
});
}
const strType = genericStruct(t.str);
const numType = genericStruct(t.num);
strType.assert({
hi: "world",
foo: "baz",
});
numType.assert({
hi: "world",
foo: 5,
});
expect(() => {
strType.assert({
hi: "world",
foo: 5,
});
}).toThrow();
expect(() => {
numType.assert({
hi: "world",
foo: "baz",
});
}).toThrow();
});