Files
typikon/npm/typecheck.ts
T
funkpower 69907eb186 javascript and typescript, as one wasm package for every runtime
WebAssembly rather than a native Node addon: one artifact serves Node,
Deno, Bun, a browser and anything built on them, where napi would have
meant a prebuilt binary per platform and a source build for whoever the
matrix missed. The engine is pure computation and the menologion is
already compiled in, so there is nothing for it to give up.

A day comes back as a plain object, not a handle. A wasm class would
have meant a .free() that every caller eventually forgets, and this way
JSON.stringify works and the thing spreads into state. Two serializer
defaults had to be overridden to keep the promise that it is the same
document --json emits: maps as objects, and an absent field as null
rather than undefined, which stringify would otherwise drop entirely.

The TypeScript is hand-written, because the generated types for a value
crossing as JsValue are `any`, and a binding that types its whole
return as `any` is a binding TypeScript cannot check. tsc --strict is a release
gate now, the way mypy --strict already is, and the check includes three
lines that must fail to compile.

The one place this differs from every other binding: no remembered
default jurisdiction, because a browser has nowhere to keep one. It is
called out in the README, in the types and in docs/versioning.md.

The test resolves typikon through a staged node_modules rather than a
relative path, so what it exercises is the exports map, and it compares
a year of days field by field against the command line for four
jurisdictions.
2026-09-18 14:55:40 -04:00

45 lines
1.5 KiB
TypeScript

// The published types, checked the way a TypeScript consumer would meet them.
// Run by npm/test.mjs. Nothing here is executed; the point is that `tsc
// --strict` accepts it, and rejects the lines below that it should.
import {
describe,
describeIso,
today,
week,
pascha,
jurisdictions,
version,
type Day,
type Options,
type JurisdictionInfo,
} from "typikon";
const opts: Options = { jurisdiction: "rocor", tradition: "slavic", typikon: true };
const day: Day = describeIso("2026-04-12", opts);
const byDate: Day = describe(new Date(), { jurisdiction: "moscow" });
const now: Day = today();
const churchDate: string = day.churchDate;
const season: string | null = day.season;
const commemorations: string[] = day.commemorations;
const daysToPascha: number = day.daysToPascha;
const seven: Day[] = week(new Date(), 7, opts);
const p: Date = pascha(2027, "old");
const all: JurisdictionInfo[] = jurisdictions();
const v: string = version();
// Referenced so nothing is unused, which --strict would otherwise let pass but
// a linter would not.
export const _ = { byDate, now, churchDate, season, commemorations, daysToPascha, seven, p, all, v };
// @ts-expect-error a season may be absent, so it is not a plain string
const wrong: string = day.season;
// @ts-expect-error there is no such option
const badOption: Options = { jurisdictionn: "rocor" };
// @ts-expect-error days is a number
const badWeek = week(new Date(), "7", opts);
export const __ = { wrong, badOption, badWeek };