javascript - typescript 用不了For In 和 Async ?
迷茫
迷茫 2017-04-10 17:26:44
[JavaScript讨论组]
/// <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框架

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(2)
怪我咯
  1. temp 你都没声明。改成 for(let temp in ... 这样。

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

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

PHP中文网

tsconfig.json里注意这两个:

    "target": "ES6",
    "module": "commonjs",
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号