TransformerFn — the type of the decorator's only argument — is missing from that second line. In the published dist/index.d.ts it appears twice: once in an internal import, once as the type of JsonTransformer. It is never re-exported.
So this does not compile against the package:
import{Transformer,typeTransformerFn}from'@green-tea/core';// ^ has no exported member 'TransformerFn'
and the workaround is to borrow the type off a value:
That works, and it reads like a trick, because it is one.
Why it matters
A custom transformer is the documented way to return anything that is not JSON, and @Transformer is a first-class decorator sitting next to @Get and @Html. Every user who writes one either declares the shape inline — losing the check that the decorator's parameter would have given them — or discovers typeof JsonTransformer.
ErrorRenderer and StreamEncoder, the two neighbouring extension points, are both exported as types. This one looks like an oversight rather than a decision.
Worth checking the same barrel for other extension-point types reachable only through a value.
Related
Found while writing the /metrics route for the green-desk demo — Prometheus scrapes text, so the handler needed its own transformer.
`Transformer` is exported and `TransformerFn` is not, so a custom transformer can be attached but not typed.
## What happens
`src/index.ts` exports the decorator:
```ts
export { ..., Transformer, Html } from './metadata';
export type { Transport, HttpMethod, RouteDecorator } from './metadata';
```
`TransformerFn` — the type of the decorator's only argument — is missing from that second line. In the published `dist/index.d.ts` it appears twice: once in an internal import, once as the type of `JsonTransformer`. It is never re-exported.
So this does not compile against the package:
```ts
import { Transformer, type TransformerFn } from '@green-tea/core';
// ^ has no exported member 'TransformerFn'
```
and the workaround is to borrow the type off a value:
```ts
const prometheusText: typeof JsonTransformer = (value) => ({
status: 200,
headers: { 'content-type': 'text/plain; version=0.0.4; charset=utf-8' },
body: String(value),
});
```
That works, and it reads like a trick, because it is one.
## Why it matters
A custom transformer is the documented way to return anything that is not JSON, and `@Transformer` is a first-class decorator sitting next to `@Get` and `@Html`. Every user who writes one either declares the shape inline — losing the check that the decorator's parameter would have given them — or discovers `typeof JsonTransformer`.
`ErrorRenderer` and `StreamEncoder`, the two neighbouring extension points, are both exported as types. This one looks like an oversight rather than a decision.
## Scope
One line in `src/index.ts`:
```ts
export type { Transport, HttpMethod, RouteDecorator, TransformerFn } from './metadata';
```
Worth checking the same barrel for other extension-point types reachable only through a value.
## Related
Found while writing the `/metrics` route for the `green-desk` demo — Prometheus scrapes text, so the handler needed its own transformer.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Transformeris exported andTransformerFnis not, so a custom transformer can be attached but not typed.What happens
src/index.tsexports the decorator:TransformerFn— the type of the decorator's only argument — is missing from that second line. In the publisheddist/index.d.tsit appears twice: once in an internal import, once as the type ofJsonTransformer. It is never re-exported.So this does not compile against the package:
and the workaround is to borrow the type off a value:
That works, and it reads like a trick, because it is one.
Why it matters
A custom transformer is the documented way to return anything that is not JSON, and
@Transformeris a first-class decorator sitting next to@Getand@Html. Every user who writes one either declares the shape inline — losing the check that the decorator's parameter would have given them — or discoverstypeof JsonTransformer.ErrorRendererandStreamEncoder, the two neighbouring extension points, are both exported as types. This one looks like an oversight rather than a decision.Scope
One line in
src/index.ts:Worth checking the same barrel for other extension-point types reachable only through a value.
Related
Found while writing the
/metricsroute for thegreen-deskdemo — Prometheus scrapes text, so the handler needed its own transformer.