Giter Club home page Giter Club logo

Comments (3)

whxaxes avatar whxaxes commented on June 30, 2024 2

还有一个办法,将 egg-ts-helper 升到 1.10.0 ,在 typings/index.d.ts 中添加这么一个声明来复写掉 model 的类型

import { MongooseModels } from 'egg';

declare module 'egg' {
  interface IModel extends MongooseModels {}

  // extend app
  interface Application {
    model: IModel;
  }

  // extend context
  interface Context {
    model: IModel;
  }
}

然后就可以了

from egg-ts-helper.

whxaxes avatar whxaxes commented on June 30, 2024

egg-mongoose 组件里的声明中的 MongooseModels 的类型是一个 type,而不是一个 interface ,而 interface 和 type 是没法做声明合并的,所以 egg-ts-helper 没法往这个 MongooseModels 挂载方法,解决方案是:

  1. 提个 PR ,把 egg-mongoose 中的 MongooseModels 改成 interface。
  2. 然后在项目下加个 tshelper.js,然后 js 中添加以下这段代码即可自动生成
module.exports = {
  watchDirs: {
    model: {
      framework: 'egg',
      interface: 'MongooseModels',
    }
  }
}

目前生成的 typings 是会有问题的,因为 MongooseModels 是 type

from egg-ts-helper.

Micjoyce avatar Micjoyce commented on June 30, 2024

我本来是通过在tshelper.js禁用

watchDirs: {
    model: false
  }

然后手动写model,你这个方法已经非常OK
非常谢谢

from egg-ts-helper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.