# ts转成mbt有啥更好的办法？

**URL:** <https://taolun.moonbitlang.com/t/topic/772>\
**Category:** 代码帮助\
**Created:** [2024 年6 月 3 日 03:49 UTC](https://taolun.moonbitlang.com/t/topic/772 "2024-06-03T03:49:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

作者： ![shiren1118](https://taolun.moonbitlang.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@shiren1118](https://taolun.moonbitlang.com/u/shiren1118)\
发布日期： [2024 年6 月 3 日 03:49 UTC](https://taolun.moonbitlang.com/t/topic/772/1 "2024-06-03T03:49:55Z")

</div>

下面koa 的 ts声明，我想把它转成mbt有啥更好的办法？

1、没有any，有的时候卡的很难受  
2、基础类型需要写，工作量很大

```auto
https://www.npmjs.com/package/@types/koa?activeTab=code

declare class Application<
    StateT = Application.DefaultState,
    ContextT = Application.DefaultContext,
> extends EventEmitter {
    proxy: boolean;
    proxyIpHeader: string;
    maxIpsCount: number;
    middleware: Array<Application.Middleware<StateT, ContextT>>;
    subdomainOffset: number;
    env: string;
    context: Application.BaseContext & ContextT;
    request: Application.BaseRequest;
    response: Application.BaseResponse;
    silent: boolean;
    keys: Keygrip | string[];
    ctxStorage: AsyncLocalStorage<ContextT> | undefined;

    /**
     * @param {object} [options] Application options
     * @param {string} [options.env='development'] Environment
     * @param {string[]} [options.keys] Signed cookie keys
     * @param {boolean} [options.proxy] Trust proxy headers
     * @param {number} [options.subdomainOffset] Subdomain offset
     * @param {string} [options.proxyIpHeader] Proxy IP header, defaults to X-Forwarded-For
     * @param {number} [options.maxIpsCount] Max IPs read from proxy IP header, default to 0 (means infinity)
     * @param {boolean} [options.asyncLocalStorage] Enable AsyncLocalStorage
     */
    constructor(options?: {
        env?: string | undefined;
        keys?: string[] | undefined;
        proxy?: boolean | undefined;
        subdomainOffset?: number | undefined;
        proxyIpHeader?: string | undefined;
        maxIpsCount?: number | undefined;
        asyncLocalStorage?: boolean | undefined;
    });

    /**
     * Shorthand for:
     *
     * http.createServer(app.callback()).listen(...)
     */
    listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): Server;
    listen(port: number, hostname?: string, listeningListener?: () => void): Server;
    listen(port: number, backlog?: number, listeningListener?: () => void): Server;
    listen(port: number, listeningListener?: () => void): Server;
    listen(path: string, backlog?: number, listeningListener?: () => void): Server;
    listen(path: string, listeningListener?: () => void): Server;
    listen(options: ListenOptions, listeningListener?: () => void): Server;
    listen(handle: any, backlog?: number, listeningListener?: () => void): Server;
    listen(handle: any, listeningListener?: () => void): Server;

    /**
     * Return JSON representation.
     * We only bother showing settings.
     */
    inspect(): any;

    /**
     * Return JSON representation.
     * We only bother showing settings.
     */
    toJSON(): any;

    /**
     * Use the given middleware `fn`.
     *
     * Old-style middleware will be converted.
     */
    use<NewStateT = {}, NewContextT = {}>(
        middleware: Application.Middleware<StateT & NewStateT, ContextT & NewContextT>,
    ): Application<StateT & NewStateT, ContextT & NewContextT>;

    /**
     * Return a request handler callback
     * for node's native http/http2 server.
     */
    callback(): (req: IncomingMessage | Http2ServerRequest, res: ServerResponse | Http2ServerResponse) => Promise<void>;

    /**
     * Initialize a new context.
     *
     * @api private
     */
    createContext<StateT = Application.DefaultState>(
        req: IncomingMessage,
        res: ServerResponse,
    ): Application.ParameterizedContext<StateT>;

    /**
     * Default error handler.
     *
     * @api private
     */
    onerror(err: Error): void;

    /**
     * return current context from async local storage
     */
    readonly currentContext: ContextT | undefined;
}

```

---

<div class="post-metadata">

作者： ![jimwei](https://taolun.moonbitlang.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@jimwei](https://taolun.moonbitlang.com/u/jimwei)\
发布日期： [2024 年12 月 14 日 12:52 UTC](https://taolun.moonbitlang.com/t/topic/772/2 "2024-12-14T12:52:41Z")

</div>

我也觉得没有Any或者Object或者Interface{}太难受了

---

<div class="post-metadata">

作者： ![tiye](https://taolun.moonbitlang.com/user_avatar/taolun.moonbitlang.com/tiye/32/401_2.png) [@tiye](https://taolun.moonbitlang.com/u/tiye)\
发布日期： [2024 年12 月 15 日 07:00 UTC](https://taolun.moonbitlang.com/t/topic/772/3 "2024-12-15T07:00:41Z")

</div>

参数复杂的代码绑的时候吃力 +1

---

<div class="post-metadata">

作者： ![hackwaly](https://taolun.moonbitlang.com/user_avatar/taolun.moonbitlang.com/hackwaly/32/60_2.png) [@hackwaly](https://taolun.moonbitlang.com/u/hackwaly)\
发布日期： [2025 年3 月 1 日 15:38 UTC](https://taolun.moonbitlang.com/t/topic/772/4 "2025-03-01T15:38:43Z")

</div>

这个可能相关？ [GitHub - CAIMEOX/ts2moonbit: Generate MoonBit bindings from TypeScript definitions via the TypeScript compiler API](https://github.com/CAIMEOX/ts2moonbit)
