mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Simplify/improve marko/express definitions (#37561)
This commit is contained in:
parent
13ad568eaa
commit
167029da71
16
types/marko/express.d.ts
vendored
16
types/marko/express.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user