Files
DefinitelyTyped/types/next/next-tests.ts
Drew Hays 0429e70ac5 Fix a few next.js type issues (#18262)
- Some of the `render` parameters should've been made optional.
- The export style of the `'next'` module wasn't correct.
- Added some missing static methods to `Head`
- Some readonly properties of `Router` can be `undefined`.

Note that this also means that `'next'` technically needs to be imported
like `import next = require('next');`
2017-07-24 10:32:29 -07:00

57 lines
2.0 KiB
TypeScript

import createServer = require('next');
import * as http from 'http';
import * as url from 'url';
const defaultServer = createServer();
const server = createServer({
dir: '..',
quiet: true,
conf: {
distDir: './dist',
useFileSystemPublicRoutes: false,
anotherProperty: {
key: true
}
},
});
const voidFunc = () => {};
const stringFunc = (x: string) => x.split('\n');
server.prepare().then(voidFunc);
server.close().then(voidFunc);
server.defineRoutes().then(voidFunc);
server.start().then(voidFunc);
const parsedUrl = url.parse('https://www.example.com');
const handler = server.getRequestHandler();
function handle(req: http.IncomingMessage, res: http.ServerResponse) {
handler(req, res);
handler(req, res, parsedUrl).then(voidFunc);
server.run(req, res, parsedUrl).then(voidFunc);
server.render(req, res, '/path/to/resource').then(voidFunc);
server.render(req, res, '/path/to/resource', {}, parsedUrl).then(voidFunc);
server.render(req, res, '/path/to/resource', { key: 'value' }, parsedUrl).then(voidFunc);
server.renderError(new Error(), req, res, '/path/to/resource').then(voidFunc);
server.renderError(new Error(), req, res, '/path/to/resource', { key: 'value' }).then(voidFunc);
server.renderError('this can be an error, too!', req, res, '/path/to/resource', { key: 'value' }).then(voidFunc);
server.render404(req, res, parsedUrl).then(voidFunc);
server.renderToHTML(req, res, '/path/to/resource', { foo: 'bar' }).then(x => x.split('\n'));
server.renderErrorToHTML(new Error(), req, res, '/path/to/resource', { foo: 'bar' }).then(x => x.split('\n'));
server.serveStatic(req, res, '/path/to/thing').then(voidFunc);
let b: boolean;
b = server.isServeableUrl('/path/to/thing');
b = server.isInternalUrl(req);
b = server.handleBuildId('{buildId}', res);
const s: string = server.readBuildId();
server.getCompilationError('page', req, res).then(err => err.thisIsAnAny);
server.handleBuildHash('filename', 'hash', res);
server.send404(res);
}