fix(types): export the extension-point types, not just the extension points
`Transformer` was exported and `TransformerFn` was not, so a custom transformer could
be attached but not typed. The workaround is to borrow the type off a value —
`const text: typeof JsonTransformer = ...` — which works and reads like a trick,
because it is one. `ErrorRenderer` and `StreamEncoder`, the two neighbouring extension
points, were both already exported; this one was an oversight rather than a decision.
Checking the rest of the barrel for the same shape turned up four more. A plugin split
into named functions rather than one inline arrow cannot annotate what it receives:
`Plugin` types the arrow, and `PluginApi`, `ScopeApi` and `ScopeNode` — the chain
reached through `api.scope.add`, which is how a plugin contributes to the graph — were
all unreachable. So was `Hooks`, which makes `createApp({ hooks })` typeable only
inline, and `TeardownFn`, the shape every one of those three doors takes.
Types only. Nothing at runtime moves, and no existing export changes.
Covered by a type test that fails to compile if any of them leaves the barrel again,
including the two that were already there — the failure mode this fixes is a barrel
edit nobody notices until a user writes the annotation.
Closes #66.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+73
-3
No files matched your search
+1
-1
@@ -41,7 +41,7 @@ import type { App, InspectLine, Explain, RoutePlan, MeshConfig } from './types';
|
||||
import { inspectRoute, buildGraphView, explainRoute } from './introspect';
|
||||
import { compilePattern } from '../http/router';
|
||||
|
||||
export type { App, InspectLine, ExplainNode, Explain, MeshConfig } from './types';
|
||||
export type { App, InspectLine, ExplainNode, Explain, MeshConfig, Hooks } from './types';
|
||||
|
||||
type Runner = (ctx: any) => any;
|
||||
|
||||
|
||||
+4
-2
@@ -40,8 +40,10 @@ export {
|
||||
Options,
|
||||
Html,
|
||||
} from './metadata';
|
||||
export type { Transport, HttpMethod, RouteDecorator } from './metadata';
|
||||
export type { Plugin } from './plugin';
|
||||
export type { Transport, HttpMethod, RouteDecorator, TransformerFn } from './metadata';
|
||||
export type { Plugin, PluginApi, ScopeApi, ScopeNode } from './plugin';
|
||||
export type { Hooks } from './app';
|
||||
export type { TeardownFn } from './lifecycle';
|
||||
|
||||
// Transformers & error signals
|
||||
export { JsonTransformer } from './transformers';
|
||||
|
||||
Reference in new issue
Block a user