typescript 用不了For In 和 Async ?

发布于 2022-09-04 02:00:57 字数 873 浏览 31 评论 0

/// <reference path="../../../typings/index.d.ts" />

'use strict';

import * as AV from 'leanengine';

class Todo extends AV.Object {}

AV.Object.register(Todo);

/**
 * model
 */
export default {
  class: Todo,

  save(todo: Todo, attr_map : Object): AV.Promise{

    for(temp in Object.keys(attr_map)){
      todo.set(temp, attr_map[temp])

    }

    return todo.save()
  }

}

temp is not defined

这个错误是报的我莫名其妙啊,百撕不得解开一观。

  async indexAction(){

    let todo_inst = new todo.class()
    
    await todo.save(todo_inst, {
      content: "test",
      name: "yugo"
    })

    console.log( todo_inst)


    this.assign({
      isIndex: true
    })
    return this.display();
  }

这个async是红色的,能运行但是subl报错,讲道理ts兼容es6啊。

ThinkJS框架

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平安喜乐 2022-09-11 02:00:57
  1. temp 你都没声明。改成 for(let temp in ... 这样。

  2. async 不是 ES6 语法。在 tsconfig 中设置 experimentalDecorators 为 true 方可。

  3. 使用 ts 开发,建议换到 VSCode。

岁吢 2022-09-11 02:00:57

tsconfig.json里注意这两个:

    "target": "ES6",
    "module": "commonjs",
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文