typescript 用不了For In 和 Async ?

/// <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框架

阅读 4.7k
2 个回答
  1. temp 你都没声明。改成 for(let temp in ... 这样。

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

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

tsconfig.json里注意这两个:

    "target": "ES6",
    "module": "commonjs",
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题