Simplify/improve marko/express definitions (#37561)

This commit is contained in:
Timur Manyanov 2019-08-15 20:50:47 +02:00 committed by Pranav Senthilnathan
parent 13ad568eaa
commit 167029da71
2 changed files with 12 additions and 24 deletions

View File

@ -1,20 +1,10 @@
import * as express from 'express';
import Template from './src/runtime/html/Template';
import { IRouterMatcher as ExpressRouterMatcher, NextFunction, PathParams } from 'express-serve-static-core';
declare function m(): m.Application;
declare namespace m {
interface Response extends express.Response {
declare module 'express-serve-static-core' {
interface Response {
marko(template: Template, data?: any): void;
}
interface Application extends express.Application {
get: ((name: string) => any) & ExpressRouterMatcher<this> & MarkoRouterMatcher;
}
type MarkoRouterMatcher = (path: PathParams, ...handlers: RequestHandler[]) => Application;
type RequestHandler = (req: express.Request, res: Response, next?: NextFunction) => any;
}
export = m;
export = express;

View File

@ -1,9 +1,9 @@
import { createServer } from 'http';
import { createWriteStream } from 'fs';
import express = require('express');
import asyncWriter = require('async-writer');
import * as express from 'express';
import * as asyncWriter from 'async-writer';
import markoExpress = require('marko/express');
import * as markoExpress from 'marko/express';
import { load } from 'marko';
import { createWriter, AsyncStream, Template, RenderResult } from 'marko/src/runtime/html';
import { Component } from 'marko/src/components';
@ -49,10 +49,8 @@ template.render({ name: 'Frank' }, writeStream);
// $ExpectType WriteStream
template.stream({}).pipe(writeStream);
(req: Request) => {
// $ExpectType Readable
template.stream({ name: 'Frank' });
};
// $ExpectType Readable
template.stream({ name: 'Frank' });
// rendering tests
@ -114,13 +112,13 @@ template.render({}, asyncWriterInstance);
// markoExpress() tests
const app = express() as markoExpress.Application;
const app = express();
// $ExpectType Application
// $ExpectType Express
app.use(markoExpress());
// $ExpectType Application
app.get('/', (req: express.Request, res: markoExpress.Response) => {
// $ExpectType Express
app.get('/', (req: express.Request, res: express.Response) => {
// $ExpectType void
res.marko(template, {
name: 'Frank',