专栏名称: 奇舞周刊
《奇舞周刊》是由奇舞团维护的前端技术周刊。除周五外,每天向大家推荐一篇前端相关技术文章,每周五向大家推送周刊汇总内容。
目录
相关文章推荐
前端早读课  ·  【第3526期】通过 MCP ... ·  昨天  
阿杜书馆  ·  5个儿子养不了一个妈! ... ·  昨天  
阿杜书馆  ·  5个儿子养不了一个妈! ... ·  昨天  
51好读  ›  专栏  ›  奇舞周刊

ThinkJS 3.0 如何实现对 TypeScript 的支持

奇舞周刊  · 公众号  · 前端  · 2017-11-15 11:29

正文

请到「今天看啥」查看全文


think . app

经过验证果然行得通,准备添加更多实现。

基本雏形

接下来先实现一版基本的架子,这个架子基本上反应了 ThinkJS 里面最重要的类和他们之间的关系。

import * as Koa from 'koa';

import * as Helper from 'think-helper';

import * as ThinkCluster from 'think-cluster';


declare namespace 'ThinkJS' {


  export interface Application extends Koa {

    think: Think;

    request: Request;

    response: Response;

  }


  export interface Request extends Koa.Request {

  }


  export interface Response extends Koa.Response {

  }


  export interface Context extends Koa.Context {

    request: Request;

    response: Response;

  }


  export interface Controller {

    new(ctx: Context): Controller;

    ctx: Context;

    body: any;

  }


  export interface Service {

    new(): Service;

  }


  export interface Logic {

    new(): Logic;

  }


  export interface Think extends Helper.Think {

    app: Application;

    Controller: Controller;

    Logic: Logic;

    Service: Service;

  }


  export var think: Think;

}


export = ThinkJS;

这里面定义到的类都是 ThinkJS 里面支持扩展的类型,为了简洁起见省略了许多方法和字段的定义,需要指出的是 Controller Service Logic 这三个接口需要被继承 extends







请到「今天看啥」查看全文