Skip to content

Commit 023a8d1

Browse files
committed
fix(devx): declare import-prerequisite's loaders so a .mts gate can import them without TS7016
`check-exported-any-returns.mts` is inside the ROOT tsc program, where an untyped `.mjs` import is TS7016 — measured, not assumed: converting it added exactly one error (169 vs the 168 the same tree reports with the unconverted file), and `@objectstack/spec-monorepo` is a shrink-only ratchet. The sidecar is the shape three root scripts already use for the same reason, and `check:declaration-mirrors` covers it by discovery. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk
1 parent 3b8b328 commit 023a8d1

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

scripts/import-prerequisite.d.mts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Types for the two dependency loaders `import-prerequisite.mjs` publishes to
2+
// the gates that import it.
3+
//
4+
// The module itself stays `.mjs` for the reason its three sibling mirrors
5+
// state: `pre-commit` and the gates invoke these scripts with bare `node`, and
6+
// every root script here is authored that way. What needs the declaration is
7+
// the other direction -- a TypeScript-authored gate (`.mts`) importing a loader
8+
// from inside the ROOT tsc program, where an untyped `.mjs` import is TS7016.
9+
// `check-exported-any-returns.mts` is the first such consumer; without this
10+
// file its conversion would have added one error to the `@objectstack/spec-
11+
// monorepo` entry of `check:type-check-debt`, a shrink-only ratchet.
12+
//
13+
// PARTIAL on purpose, the `check-regen-pending.d.mts` shape: the module also
14+
// exports the exit-code constants, the classifier and its self-test, and
15+
// omitting them cannot fail green -- a consumer importing an undeclared name
16+
// gets TS2305, which is loud and immediate. Keep this file in step with the
17+
// module by hand; `check:declaration-mirrors` checks name, kind and required
18+
// arity, never types.
19+
//
20+
// ⛔ The return type is `any` BY MEASUREMENT, not by omission: what these
21+
// return is whatever the loaded package exports, and the 27 `.mjs` call sites
22+
// already bind it untyped. A consumer that wants the real namespace types
23+
// declares them itself -- `check-exported-any-returns.mts` keeps an erased
24+
// `import type TS from 'typescript'` beside the runtime binding for exactly
25+
// that, and a `typescript`-shaped return here would be a lie at every other
26+
// call site (`yaml`, `semver`, `eslint`, `github-slugger`).
27+
28+
/**
29+
* Load a dependency, or print a named `PREREQUISITE NOT MET` diagnosis and exit
30+
* `EXIT_PREREQUISITE_NOT_MET` (3). Resolves to the module NAMESPACE.
31+
*
32+
* @param specifier The bare specifier, e.g. `'@typescript-eslint/parser'`.
33+
* @param load `() => import('@typescript-eslint/parser')`, written in the CALLER
34+
* so the failing resolution is the caller's own.
35+
* @param importerUrl The caller's `import.meta.url`.
36+
* @param options `measures` is what the gate would have judged, in the gate's
37+
* own words -- the one half of the refusal text that is never shared.
38+
*/
39+
export function requireDependency(
40+
specifier: string,
41+
load: () => Promise<unknown>,
42+
importerUrl: string,
43+
options?: { measures?: string },
44+
): Promise<any>;
45+
46+
/**
47+
* `requireDependency` for the DEFAULT export -- the shape `import ts from
48+
* 'typescript'` had. Reads `.default` strictly rather than falling back to the
49+
* namespace.
50+
*
51+
* @param specifier The bare specifier, e.g. `'typescript'`.
52+
* @param load `() => import('typescript')`, written in the CALLER.
53+
* @param importerUrl The caller's `import.meta.url`.
54+
* @param options `measures` is what the gate would have judged, in the gate's
55+
* own words.
56+
*/
57+
export function requireDefaultExport(
58+
specifier: string,
59+
load: () => Promise<unknown>,
60+
importerUrl: string,
61+
options?: { measures?: string },
62+
): Promise<any>;

0 commit comments

Comments
 (0)