Skip to content

Commit 2e14e1a

Browse files
authored
Merge pull request #367 from preactjs/fix/stream-types
fix: Add types for renderStream & pipeableStream
2 parents ae55a6c + 8c7e08f commit 2e14e1a

File tree

7 files changed

+75
-12
lines changed

7 files changed

+75
-12
lines changed

.changeset/slimy-eagles-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string': patch
3+
---
4+
5+
Add types for `/stream` and `/stream-node` exports

jsx.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ interface Options {
1010
skipFalseAttributes?: boolean;
1111
}
1212

13-
export default function render(
13+
export default function renderToStringPretty(
1414
vnode: VNode,
1515
context?: any,
1616
options?: Options
1717
): string;
18+
export function render(vnode: VNode, context?: any, options?: Options): string;
1819

19-
export function shallowRender(vnode: VNode, context?: any): string;
20+
export function shallowRender(
21+
vnode: VNode,
22+
context?: any,
23+
options?: Options
24+
): string;

package-lock.json

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"bench": "BABEL_ENV=test node -r @babel/register benchmarks index.js",
4141
"bench:v8": "BABEL_ENV=test microbundle benchmarks/index.js -f modern --alias benchmarkjs-pretty=benchmarks/lib/benchmark-lite.js --external none --target node --no-compress --no-sourcemap --raw -o benchmarks/.v8.mjs && v8 --module benchmarks/.v8.modern.js",
4242
"build": "npm run -s transpile && npm run -s transpile:jsx && npm run -s transpile:stream && npm run -s transpile:stream-node && npm run -s copy-typescript-definition",
43-
"postbuild": "node ./config/node-13-exports.js && node ./config/node-commonjs.js && node ./config/node-verify-exports.js",
43+
"postbuild": "node ./config/node-13-exports.js && node ./config/node-commonjs.js && node ./config/node-verify-exports.js && check-export-map",
4444
"transpile": "microbundle src/index.js -f es,cjs,umd",
4545
"transpile:stream": "microbundle src/stream.js -o dist/stream/index.js -f es,cjs,umd",
4646
"transpile:stream-node": "microbundle src/stream-node.js -o dist/stream/node/index.js -f es,cjs,umd --target node",
@@ -132,16 +132,17 @@
132132
"@babel/register": "^7.12.10",
133133
"@changesets/changelog-github": "^0.4.1",
134134
"@changesets/cli": "^2.18.0",
135+
"baseline-rts": "npm:preact-render-to-string@latest",
135136
"benchmarkjs-pretty": "^2.0.1",
136137
"chai": "^4.2.0",
138+
"check-export-map": "^1.3.1",
137139
"copyfiles": "^2.4.1",
138140
"eslint": "^7.16.0",
139141
"eslint-config-developit": "^1.2.0",
140142
"husky": "^4.3.6",
141143
"lint-staged": "^10.5.3",
142144
"microbundle": "^0.15.1",
143145
"mocha": "^8.2.1",
144-
"baseline-rts": "npm:preact-render-to-string@latest",
145146
"preact": "^10.13.0",
146147
"prettier": "^2.2.1",
147148
"pretty-format": "^3.8.0",

src/stream-node.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { VNode } from 'preact';
2+
import { WritableStream } from 'node:stream';
3+
4+
interface RenderToPipeableStreamOptions {
5+
onShellReady?: () => void;
6+
onAllReady?: () => void;
7+
onError?: (error: any) => void;
8+
}
9+
10+
interface PipeableStream {
11+
abort: () => void;
12+
pipe: (writable: WritableStream) => void;
13+
}
14+
15+
export function renderToReadableStream(
16+
vnode: VNode,
17+
options: RenderToPipeableStreamOptions,
18+
context?: any
19+
): PipeableStream;

src/stream-node.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ import { renderToChunks } from './lib/chunked.js';
88
* @property {(error) => void} [onError]
99
*/
1010

11+
/**
12+
* @typedef {object} PipeableStream
13+
* @property {() => void} abort
14+
* @property {(writable: import('stream').Writable) => void} pipe
15+
*/
16+
1117
/**
1218
* @param {import('preact').VNode} vnode
1319
* @param {RenderToPipeableStreamOptions} options
1420
* @param {any} [context]
15-
* @returns {{}}
21+
* @returns {PipeableStream}
1622
*/
1723
export function renderToPipeableStream(vnode, options, context) {
1824
const encoder = new TextEncoder('utf-8');

src/stream.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { VNode } from 'preact';
2+
3+
interface RenderStream extends ReadableStream<Uint8Array> {
4+
allReady: Promise<void>;
5+
}
6+
7+
export function renderToReadableStream(
8+
vnode: VNode,
9+
context?: any
10+
): RenderStream;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy